Create HTML E-mails with embedded image
// Create the HTML message body // Reference embedded images using the content ID string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:Pic1\"></body></html>"; AlternateView avHtml = AlternateView.CreateAlternateViewFromString (htmlBody, null, MediaTypeNames.Text.Html);
// Create a LinkedResource object for each embedded image LinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg); pic1.ContentId = "Pic1"; avHtml.LinkedResources.Add(pic1);
// Create an alternate view for unsupported clients string textBody = "You must use an e-mail client that supports HTML messages"; AlternateView avText = AlternateView.CreateAlternateViewFromString (textBody, null, MediaTypeNames.Text.Plain);
// Add the alternate views instead of using MailMessage.Body MailMessage m = new MailMessage(); m.AlternateViews.Add(avHtml); m.AlternateViews.Add(avText);
// Address and send the message m.From = new MailAddress(FrommailId, "kk"); m.To.Add(new MailAddress(TomailId", "kk")); m.Subject = "A picture using alternate views"; SmtpClient client = new SmtpClient(smptip); client.Send(m);
|
No responses found. Be the first to respond and make money from revenue sharing program.
|