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.4 build 677 for .NET 4.5
Syntax
public bool LoadBodyText(
	string path,
	MessageBodyType bodyType,
	Encoding sourceEncoding,
	ImportBodyOptions options
)

Parameters

path
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.
bodyType
Type: MailBee.MimeMessageBodyType
Denotes whether to load the data into HTML body or into plain-text body.
sourceEncoding
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).
options
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.
Exceptions
ExceptionCondition
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.
Remarks

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.

Examples
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="http://www.company.com/logo.gif">, 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);

msg.SaveMessage(@"C:\Temp\msg.eml");
See Also