sending mail along with embedded image using asp.net

If you are using .NET 2 or above you can use the AlternateView and LinkedResource classes like this:

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

LinkedResource yourPictureRes = new LinkedResource("yourPicture.jpg", MediaTypeNames.Image.Jpeg);
yourPictureRes.ContentId = "YourPictureId";
altView.LinkedResources.Add(yourPictureRes);

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

Hopefully you can deduce the VB equivalent.

Leave a Comment