Multipart Mime Email Messages in Dot Net

Here I am posting complete code related to my previous post ‘Embedding Images in Email‘.

using System.Net.Mail;
using System.Text;
using System.Net.Mime;
using System.Net;

// other code stuff goes here

protected void SendEmail()

MailMessage mail = new MailMessage("", "");
mail.Subject = "...and life goes on ...";

//create the image resource from image path using LinkedResource class..
LinkedResource imageResource1 = new LinkedResource ("C:\images\myImg.jpg", "image/jpeg");
imageResource1.ContentId = "uniqueId1";
imageResource1.TransferEncoding = TransferEncoding.Base64;

StringBuilder htmlBody = new StringBuilder ();

string emailMsg = "Your Email message";

htmlBody.AppendLine("<img alt=\"AltText\" hspace=0 src=\"cid:uniqueId1\" border=0 >");

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody.ToString(), null, "text/html");

//adding the imaged linked to htmlView...


SmtpClient smtp = new SmtpClient ("", 587);
// If smtp server requires SSL
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("", "yourPassword");



~ by UTS on May 22, 2009.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: