MailMessage.Load

Load(string)

Load message from file

public static MailMessage Load(string fileName)
ParameterTypeDescription
fileNameStringMessage file name. The message file must be in eml or msg format.

Return Value

E-mail message

See Also


Load(Stream)

Load message from stream

public static MailMessage Load(Stream stream)
ParameterTypeDescription
streamStreamStream that represents message in eml or msg format

Return Value

E-mail message

See Also


Load(string, LoadOptions)

Load message from file with additional options.

public static MailMessage Load(string fileName, LoadOptions options)
ParameterTypeDescription
fileNameStringSource file pathString.
optionsLoadOptionsAdditional options LoadOptions.

Return Value

Mail messageMailMessage.

Exceptions

exceptioncondition
ArgumentNullExceptionIf fileName is null.

Examples

The following example shows how to load a Message with Load Options.

[C#]

// Load Eml, html, mhtml, msg and dat file 
MailMessage.Load("Message.eml", new EmlLoadOptions());
MailMessage.Load("description.html", new HtmlLoadOptions());
MailMessage.Load("Message.mhtml", new MhtmlLoadOptions());
MailMessage.Load("Message.msg", new MsgLoadOptions());

// loading with custom options
var emlLoadOptions = new EmlLoadOptions
{
    PreferredTextEncoding = Encoding.UTF8,
    PreserveTnefAttachments = true
};

MailMessage.Load("description.html", emlLoadOptions);

var htmlLoadOptions = new HtmlLoadOptions
{
    PreferredTextEncoding = Encoding.UTF8,
    ShouldAddPlainTextView = true,
    PathToResources = htmlImagesFolder
};

MailMessage.Load("description.html", htmlLoadOptions);

[Visual Basic]

' Load Eml, html, mhtml, msg and dat file
Dim mailMessage As MailMessage = MailMessage.Load("Message.eml", New EmlLoadOptions())
MailMessage.Load("description.html", New HtmlLoadOptions())
MailMessage.Load("Message.mhtml", New MhtmlLoadOptions())
MailMessage.Load("Message.msg", New MsgLoadOptions())

' loading with custom options
Dim emlLoadOptions As EmlLoadOptions = New EmlLoadOptions With {
  .PrefferedTextEncoding = Encoding.UTF8,
	.PreserveTnefAttachments = True
}

MailMessage.Load("description.html", emlLoadOptions)

Dim htmlLoadOptions As HtmlLoadOptions = New HtmlLoadOptions With {
	.PrefferedTextEncoding = Encoding.UTF8,
		.ShouldAddPlainTextView = True,
			.PathToResources = htmlImagesFolder
}
				
MailMessage.Load("description.html", emlLoadOptions)

See Also


Load(Stream, LoadOptions)

Load message from stream with additional options.

public static MailMessage Load(Stream stream, LoadOptions options)
ParameterTypeDescription
streamStreamSource streamStream.
optionsLoadOptionsAdditional options LoadOptions.

Return Value

Mail messageMailMessage.

Exceptions

exceptioncondition
ArgumentNullExceptionIf stream is null.

See Also