The embedded images are stored in the MailMessage.Resources
collection.
To convert HTML mail to ordinary HTML page, you need to manipulate the HTML mail body. You have to replace cid:ID
with appropriate string. You can either extract embedded images to files and use the filename instead of cid:ID
or embed the image data into HTML page directly like this:
foreach (var res in mail.Resources)
{
if (res.ContentId == null ||
res.MediaType == null ||
!res.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
continue;
MemoryStream ms = new MemoryStream();
using (var content = res.GetContentStream())
{
content.CopyTo(ms);
}
byte[] data = ms.ToArray();
string cidString = string.Format("cid:{0}", res.ContentId.Id);
string dataString = string.Format("data:{0};base64,{1}", res.MediaType, Convert.ToBase64String(data));
// replace image link (cid:) with image data (data:)
mail.BodyHtml = mail.BodyHtml.Replace(cidString, dataString);
}
Please note, that this code only shows the way, how to do it. To make it robust you should handle letter case and spaces in "cid:" string.