Monday, August 10, 2009

Embedding the image using image URL

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);

}

No comments:

Post a Comment