MailBee.NET Objects 4.0

MailMessage.LoadBodyText Method (String, MessageBodyType)

Loads the contents of the specified file into HTML or plain-text body of the message.

public bool LoadBodyText(
   string filename,
   MessageBodyType bodyType
);

Parameters

filename
The absolute or relative path to the file containing the text to be imported.
bodyType
Denotes whether to load the data into HTML body or into plain-text body.

Return Value

true if the text was successfully imported; otherwise, false.

Remarks

This method does not automatically attach pictures and other files referenced in the HTML content being imported. Use ImportRelatedFiles method or LoadBodyText for this. The latter can also be used to load HTML body from a web location rather than from local filesystem.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException filename is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeIOException An I/O error occurred and ThrowExceptions is true.

Example

This sample creates a new message and loads HTML body from .HTM file.

[C#]
// 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\web_page.htm", MessageBodyType.Html);
msg.SaveMessage(@"C:\Temp\msg.eml");
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

Dim msg As New MailMessage
msg.LoadBodyText("C:\Temp\web_page.htm", MessageBodyType.Html)
msg.SaveMessage("C:\Temp\msg.eml")

See Also

MailMessage Class | MailBee.Mime Namespace | MailMessage.LoadBodyText Overload List | ImportRelatedFiles | Builder