MailMessageLoadBodyText Method (String, MessageBodyType, Encoding, ImportBodyOptions) |
Namespace: MailBee.Mime
public bool LoadBodyText( string path, MessageBodyType bodyType, Encoding sourceEncoding, ImportBodyOptions options )
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | path is a null reference (Nothing in Visual Basic) or an empty string. |
MailBeeWebException | A downloading error occurred and ThrowExceptions is true. |
MailBeeIOException | An I/O error occurred and ThrowExceptions is true. |
When bodyType is Plain, this method loads the data into BodyPlainText.
When bodyType is Html, this method loads the data into BodyHtmlText and optionally adds all related files (objects referenced in the HTML body) as inline attachments. Automatic attaching of related files can be enabled with ImportRelatedFiles flag specified in options parameter.
To embed related files if the HTML body is not available as a file (for instance, if it's taken from database or created in memory), use ImportRelatedFiles(ImportRelatedFilesOptions) method. The current method simply loads the data from the file (or URL) and then calls ImportRelatedFiles(ImportRelatedFilesOptions). ImportRelatedFiles(ImportRelatedFilesOptions) topic also describes advanced topics of embedding related files into the message.
OnReplaceUriWithCid delegate provides an additional control on which referenced resources get imported and which are not.
// To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.Mime; MailMessage msg = new MailMessage(); msg.LoadBodyText(@"C:\Temp\report.htm", MessageBodyType.Html, System.Text.Encoding.Default, ImportBodyOptions.ImportRelatedFiles | ImportBodyOptions.ImportRelatedFilesFromUris); msg.SaveMessage(@"C:\Temp\msg.eml");