2

In my form, I have a picturebox that contains an image. I'm trying to figure out how to put the image from my picturebox as an attachment and in the body of my default email.

This is what I have so far:

This opens up my default email which is outlook but does not attach or paste the picture in the body.

    private void button1_Click(object sender, EventArgs e)
    {
       var url = "mailto:emailnameu@domain.com&SUBJECT=My Subject&body="+pictureBox1.Image+"&attachment=" + pictureBox1.Image;
       System.Diagnostics.Process.Start(url);
    }

This is what happens when I add this line in my variable &body="+pictureBox1.Image+ It does not paste the picture in the body but writes System.Drawing.Bitmap

enter image description here

taji01
  • 2,527
  • 8
  • 36
  • 80
  • Hi @vasek this doesn't talk about using smtp server. I'm talking about how to do it with your default email – taji01 Oct 03 '17 at 19:24
  • Sorry, picked wrong link on mobile. This is correct one: https://stackoverflow.com/questions/450115/how-do-i-popup-the-compose-create-mail-dialog-using-the-users-default-email-c – vasek Oct 03 '17 at 19:29
  • Hi @vasek no problem, but this link doesn't provide a solution to this particular issue – taji01 Oct 03 '17 at 19:31

2 Answers2

1

You can't send image content on the body using mailto, its said here

The special "body" indicates that the associated is the body of the message. The "body" field value is intended to contain the content for the first text/plain body part of the message. The "body" pseudo header field is primarily intended for the generation of short text messages for automatic processing (such as "subscribe" messages for mailing lists), not for general MIME bodies.

Also, attachments isn't officially supported for security reasons.

Community
  • 1
  • 1
4D1C70
  • 490
  • 3
  • 10
0

You can't send image using mailto:, as other answers and comments say. However there is a working way how to send image from PictureBox.

Basic idea is taken from this post. That solution only creates .eml file that is opened by associated application.

So you only need to save your PictureBox content and send it as attachment:

string tempEmail = Path.ChangeExtension(Path.GetTempFileName(), "eml");
string tempImage = Path.Combine(Path.GetTempPath(), "Attachment.jpg");

pictureBox1.Image.Save(tempImage, ImageFormat.Jpeg);

var mailMessage = new MailMessage("from@domain.com", "to@domain.com", "Subject here", "Body text here");
mailMessage.Attachments.Add(new Attachment(tempImage));
mailMessage.Save(tempEmail);

Process.Start(tempEmail);

Note you should also consider some cleanup after email client is closed.

vasek
  • 2,759
  • 1
  • 26
  • 30