Embedding Local Images for Email Clients
You have built a document in the WPF HTML Editor - a newsletter, an automated invoice receipt, an HR policy notice - and now you need to send it as an email instead of just displaying it inside your app. Documents that embed local images as data URIs often render poorly in email clients: Outlook on Windows downsizes inline images to thumbnails, and Outlook on the web can strip them entirely. This page shows how to convert the document into a ready-to-send email that keeps every image intact.
Email clients reliably render inline images that use CID-linked resources, a long-standing email standard. The WPF HTML Editor packages your document into that format directly:
System.Net.Mail.MailMessage mail = editor.Content.GetEmailMessageWithLocalImagesEmbedded();What comes back is a ready-to-send MailMessage with:
- An HTML
AlternateViewwhose body is the document, with every local<img src>rewritten to acid:reference. - One
LinkedResourceper local image attached to that alternate view, each with the matchingContentId.

Send the resulting MailMessage through your SMTP client:
using System.Net;
using System.Net.Mail;
using System.Windows;
private void SendListingEmail_Click(object sender, RoutedEventArgs e)
{
// 1. Build the MailMessage; local photos are embedded as CID resources
MailMessage mail = editor.Content.GetEmailMessageWithLocalImagesEmbedded();
// 2. Fill in the envelope
mail.From = new MailAddress("agent@immobilien.de", "Muster Immobilien");
mail.To.Add("interessent@example.de");
mail.Subject = "Ihre Anfrage: Wohnung am Stadtpark";
// 3. Send through the agency's SMTP server
using (var smtp = new SmtpClient("smtp.immobilien.de", 587))
{
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("agent@immobilien.de", "app-password");
smtp.Send(mail);
}
MessageBox.Show("Email versendet. Die Bilder reisen mit.");
}Imports System.Net
Imports System.Net.Mail
Imports System.Windows
End Sub
Private Sub SendListingEmail_Click(sender As Object, e As RoutedEventArgs)
' 1. Build the MailMessage; local photos are embedded as CID resources
Dim mail As MailMessage = editor.Content.GetEmailMessageWithLocalImagesEmbedded()
' 2. Fill in the envelope
mail.From = New MailAddress("agent@immobilien.de", "Muster Immobilien")
mail.[To].Add("interessent@example.de")
mail.Subject = "Ihre Anfrage: Wohnung am Stadtpark"
' 3. Send through the agency's SMTP server
Using smtp = New SmtpClient("smtp.immobilien.de", 587)
smtp.EnableSsl = True
smtp.Credentials = New NetworkCredential("agent@immobilien.de", "app-password")
smtp.Send(mail)
End Using
MessageBox.Show("Email versendet. Die Bilder reisen mit.")The method only embeds <img> tags whose src is a local file path the editor can read. Images that already reference an http/https URL are left as URL references, which the recipient's mail client fetches over the network. Local and remote images can coexist in the same email.
To log or inspect the attachments before sending, enumerate the linked resources under the alternate view:
var altView = (AlternateView)mail.AlternateViews[0];
foreach (LinkedResource lr in altView.LinkedResources)
{
LogAttachment(lr.ContentId, lr.ContentType.MediaType, lr.ContentStream.Length);
}Dim altView = CType(mail.AlternateViews(0), AlternateView)
For Each lr As LinkedResource In altView.LinkedResources
LogAttachment(lr.ContentId, lr.ContentType.MediaType, lr.ContentStream.Length)
Next