Solved

SMTP mail attachment (jpg) in C#

Posted on 2011-03-04
4
830 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

732 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