Embedding the image with an Email

Posted by Venkat | Labels: , ,

We have to discuss about how to Embed an image to Email Previous Article we are discussed passing image URL directly to body tag of Email.

So , now we Embed a Image directly to Email

See the example...

try

{

MailMessage mail = new MailMessage();

mail.To.Add("user@gmail.com");

mail.From = new MailAddress("admin@support.com");

mail.Subject = "Test with Image";

string Body = "<b> Welcome to Embed image!</b><br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";


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

LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"\images\sample.jpg", "image/jpg");


imagelink.ContentId = "imageId";

imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

htmlView.LinkedResources.Add(imagelink);

mail.AlternateViews.Add(htmlView);

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

//specify your smtp server name/ip here
smtp.EnableSsl = true;

//enable this if your smtp server needs SSL to communicate
smtp.Credentials = new NetworkCredential("username", "password");

// smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

smtp.Send(mail);

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

Embedding the image using image URL

Posted by Venkat | Labels: ,

Hi Good day to all

Here We have to discuss about , how to embed the image to an email actually , Embedding an image will affect performance so here , i am passing the image URL directly to the body tag

so , here the code..


try

{

MailMessage mail = new MailMessage();

mail.To.Add("user@gmail.com");

mail.From = new MailAddress("admin@support.com");

mail.Subject = "Test with Image";

string Body = "<b>Welcome to Pass Image URL to Email Body!</b><br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src='http://www.idealsd.co.uk/images/addmenu.jpg' align=baseline border=0 >";


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

mail.AlternateViews.Add(htmlView);

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

//specify your smtp server name/ip here
smtp.EnableSsl = true;

//enable this if your smtp server needs SSL to communicate
smtp.Credentials = new NetworkCredential("Username", "password");

// smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

smtp.Send(mail);

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

PayOffers.in