MailMessageImportRelatedFiles Method |
Namespace: MailBee.Mime
Exception | Condition |
---|---|
MailBeeException | An error occurred and ThrowExceptions is true. |
All links to the related files (external documents which are referenced in BodyHtmlText) are replaced with Content-IDs generated for these files when they were attached.
To detect which URIs in the HTML body reference resources which can be added as related files to the message, MailBee examines each URI and checks if it's a web resource or local file system resource. Web resources are ignored unless ImportFromUris option is specified. If the URI contains absolute path on the filesystem, this path is used to load the file. If the URI contains relative path, MailBee by gets the file from MailMessage.Builder.RelatedFilesFolder location. If MailBee was unable to find a resource based on the denoted by the given URIs, such URI is left intact and the inline attachment for that URI is not added.
OnReplaceUriWithCid delegate provides an additional control on which referenced resources get imported and which are not.
using System.IO; using MailBee; using MailBee.SmtpMail; using MailBee.Mime; class Sample { static void Main(string[] args) { // Load the HTML content from the specified file. string textHtml = string.Empty; using (StreamReader sr = new StreamReader(@"C:\Temp\web_page.htm")) { textHtml = sr.ReadToEnd(); } // Create a new message and set HTML body of this message. MailMessage msg = new MailMessage(); msg.BodyHtmlText = textHtml; // Import all related files from URIs and then send the message. msg.ImportRelatedFiles(ImportRelatedFilesOptions.ImportFromUris); Smtp.QuickSend(msg); } }