MailMessage.Load
Contents
[
Hide
]Load(string)
Loads a message from a file. MSG is recognized automatically; any other file is read as EML.
public static MailMessage Load(string fileName)
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The path of the file. |
Return Value
The loaded message.
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | fileName is null or empty. |
| FormatNotSupportedException | The format of the data is not supported. |
See Also
- class MailMessage
- namespace Aspose.Email
- assembly Aspose.Email
Load(Stream)
Loads a message from a stream. MSG is recognized automatically; any other data is read as EML.
public static MailMessage Load(Stream stream)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The stream to read. |
Return Value
The loaded message.
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | stream is null. |
| NotSupportedException | stream does not support reading. |
| FormatNotSupportedException | The format of the data is not supported. |
See Also
- class MailMessage
- namespace Aspose.Email
- assembly Aspose.Email
Load(string, LoadOptions)
Loads a message from a file in the format selected by the options.
public static MailMessage Load(string fileName, LoadOptions options)
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The path of the file. |
| options | LoadOptions | The options; their class selects the format, such as EmlLoadOptions or MsgLoadOptions. |
Return Value
The loaded message.
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | fileName is null. |
| FormatNotSupportedException | The format of the data is not supported. |
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
- class LoadOptions
- class MailMessage
- namespace Aspose.Email
- assembly Aspose.Email
Load(Stream, LoadOptions)
Loads a message from a stream in the format selected by the options.
public static MailMessage Load(Stream stream, LoadOptions options)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The stream to read. |
| options | LoadOptions | The options; their class selects the format, such as EmlLoadOptions or MsgLoadOptions. |
Return Value
The loaded message.
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | stream is null. |
| FormatNotSupportedException | The format of the data is not supported. |
See Also
- class LoadOptions
- class MailMessage
- namespace Aspose.Email
- assembly Aspose.Email