MailMessageLoadBodyText Method (String, MessageBodyType, Encoding, ImportBodyOptions)
Loads the contents of the specified file or web page into HTML or plain-text body of the message, also attaching related objects such as inline images if necessary.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public bool LoadBodyText(
	string path,
	MessageBodyType bodyType,
	Encoding sourceEncoding,
	ImportBodyOptions options


Type: SystemString
The path to the file containing the text to be loaded into the message body. This path can be an URI (such as web page URL or file path specified as file:///) if options value includes PathIsUri flag.
Type: MailBee.MimeMessageBodyType
Denotes whether to load the data into HTML body or into plain-text body.
Type: System.TextEncoding
The charset of the data in the file being loaded. If a null reference (Nothing in Visual Basic), DefaultEncoding will be assumed (unless the charset information is available in META tag of the HTML data being loaded).
Type: MailBee.MimeImportBodyOptions
A set of flags which affect how the data is loaded from the file into the message body and whether (and how) the related objects should be attached.

Return Value

Type: Boolean
true if succeeded; otherwise, false.
MailBeeInvalidArgumentExceptionpath is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeWebExceptionA downloading error occurred and ThrowExceptions is true.
MailBeeIOExceptionAn 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.

This sample creates a new message, loads HTML body from .HTM file, and adds all files referenced in this body as attachments. Although the .HTM file itself it taken from disk (not from web location), we use ImportRelatedFilesFromUris flag to make related files be attached to the message even if they are not on the local filesystem but on the web. For instance, if the .HTM file being loaded contains <IMG SRC="">, the resulting HTML body will have this text replaced with something like <IMG SRC="cid:de78fa3042283932f4e2"> and the logo.gif file will be embedded as inline attachment into the message.
// 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);

See Also