Solved

SMTP mail attachment (jpg) in C#

Posted on 2011-03-04
4
808 Views
Last Modified: 2013-11-30
I am trying to get a screen shot of the desktop and send it as a jpg as an attachment - can some one please help
//create the mail message 
            MailMessage mail = new MailMessage();
            //set the addresses 
            mail.From = new MailAddress(frm.txtBxUser.Text + "@email.com");
#if (!DEBUG) 
            mail.To.Add("email@email.com");
#endif
#if DEBUG
            mail.To.Add("email@email.com");
#endif
            mail.Bcc.Add("email@email.com");
            //set the content 
            mail.Subject = "user 1 is here - " + frm.strContainer;
            mail.Body = frm.txtBxUser.Text + " " + "typed a word deemed inappropriate. That word was:" + " " + statement.ToString() + " " + "on" + " " + DateTime.Now;
            //add the attachment and take the screen shot
            int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
            int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
            Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
            Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
            
            gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
            bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);
            
            //string file = "test.jpg";
            Attachment file = new Attachment(file, MediaTypeNames.Application.Octet);
            mail.Attachments.Add(file);
            //send the message 
            SmtpClient smtp = new SmtpClient("00.00.0.00");//or 00.00.0.00
            smtp.Credentials = new System.Net.NetworkCredential("user", "pass");
            smtp.Send(mail);

Open in new window

0
Comment
Question by:r3nder
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35040120
Which part is failing?
0
 
LVL 6

Author Comment

by:r3nder
ID: 35040151
I am trying to create the screenshot as test.jpg and attach it - thats seems to be the part that's failing
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 35040567
on this line:
Attachment file = new Attachment(file, MediaTypeNames.Application.Octet);

you are not refering the filename! try:
Attachment file = new Attachment("test.jpg", MediaTypeNames.Application.Octet);
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 35059122
Right on the money
Thanks emoreau!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 63
VB.NET (2008) - Refactoring Question 2 21
application restarter  - for an exe that hangs 9 26
VB.NET 2008 - SQL Timeout 9 24
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question