0

to specify the question: I'm creating a bitmap object, which I want to send with an email. I don't want to save it before or upload it to a webserver. Just attach it and then link the attachement in the html body of the mail. I've searched quite a time now and all I can find are answers in which the picture is stored in the file system or on a server.

So is there any way to do this whithout saving the image before?

Thanks

Edit: I've tried around a bit and finally came to this solution:

            MailMessage mail = new MailMessage();
            mail.To.Add(new MailAddress("xxx@yyy.de"));
            mail.From = new MailAddress("xxx@yyy.de");
            SmtpClient sender = new SmtpClient
            {
                Host = "smtp.client",
                Port = 25
            };
            mail.Subject = "test";

            body= "blablabla<br><img alt=\"\" hspace=0 src=\"cid:ImagedId\" align=baseline border=0 ><br>blablabla";
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");

            using (System.IO.MemoryStream image = new System.IO.MemoryStream())
            {
                Bitmap diagram = new Bitmap("C:\\qwer.bmp");
                diagram.Save(image, System.Drawing.Imaging.ImageFormat.Jpeg);
                LinkedResource resource = new LinkedResource(image, "image/jpeg");
                resource.ContentId = "ImageId";
                resource.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                htmlView.LinkedResources.Add(resource);
                mail.AlternateViews.Add(htmlView);

                sender.Send(mail);
            }

But now my MailClient (Lotus Notes) doesnt open the mail with the error: "no mime data". Any Idea how to solve this?

Lowallyn
  • 1
  • 2
  • Maybe [this question](http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email) can help. There are some good answers there. – Geeky Guy May 02 '13 at 15:33
  • 1
    thanks, this question got me on the right track. Just need to solve the "no mime data" problem now... – Lowallyn May 07 '13 at 15:15

1 Answers1

0

Try creating it in Word (either just the image or whole email) then drag over it and copy and paste into Outlook. I think that auto attaches images as well as embeds them.

John
  • 11,985
  • 3
  • 45
  • 60