Sumit Goyal
Sumit Goyal

Reputation: 165

How to send HTML email with multiple Images

i want to send html mail with multiple images. i am using webbrowsercontrol to embedded multiple images but when i send mail HTML email along with Image in HTML then I receive only html mail without Image.!

Upvotes: 1

Views: 2435

Answers (1)

Murali Murugesan
Murali Murugesan

Reputation: 22619

Try with LinkedResource Class to embed the image

using System.Net.Mail;

string messageHtml= @"<html><body> Your message text 
                  <img src=""cid:12345"" />
                  <img src=""cid:123456"" /></body></html>";
AlternateView view= AlternateView.CreateAlternateViewFromString(messageHtml, null, MediaTypeNames.Text.Html);

LinkedResource pic= new LinkedResource("pics.jpg", MediaTypeNames.Image.Jpeg);
pic.ContentId = "12345";

LinkedResource pic2= new LinkedResource("pic2.jpg", MediaTypeNames.Image.Jpeg);
pic2.ContentId = "123456";
view.LinkedResources.Add(pic);
view.LinkedResources.Add(pic2);

MailMessage mail = new MailMessage();
mail.AlternateViews.Add(view);

mail.send();

Upvotes: 5

Related Questions