My Technical Notes

Wednesday, 3 December 2014

C# - Inserting Images in an Email


string htmlBody = @"<html><body><img src='cid:myPicture' /></body></html>";
var altView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);

var imageResource = new LinkedResource("C:\...\picture.jpg", MediaTypeNames.Image.Jpeg);
imageResource.ContentId = "myPicture";
altView.LinkedResources.Add(imageResource);

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

No comments: