.NET

From Richard's Wiki
Revision as of 20:48, 10 October 2011 by Rkdrm (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • To add an image from a resource to an HTML email using the System.Net.Mail namespace:
 using System.Drawing.Imaging;
 using System.IO;
 using System.Net.Mail;
 using System.Net.Mime;
 ...
 string logoCid = "logo";
 MemoryStream logoStream = new MemoryStream();
 Resources.Logo.Save(logoStream, ImageFormat.Jpeg);
 logoStream.Seek(0, SeekOrigin.Begin);
 LinkedResource logo = new LinkedResource(logoStream, MediaTypeNames.Image.Jpeg) { ContentId = logoCid };
 string fmt = @"<table style='width:100%;'><tr><td><img align='left' src='cid:{0}'></td></tr></table>";
 string html = string.Format(fmt, logoCid);
 AlternateView htmlView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
 htmlView.LinkedResources.Add(logo);
Improving Performance of .Net Forms Applications