[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SMTP mail attachment (jpg) in C#

Posted on 2011-03-04
4
Medium Priority
?
865 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
Starting up a Project
Suggested Courses

656 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