MimeMessageLoadAsync(ParserOptions, Stream, CancellationToken) Method

Asynchronously load a MimeMessage from the specified stream.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static Task<MimeMessage> LoadAsync(
	ParserOptions options,
	Stream stream,
	CancellationToken cancellationToken = default
)

Parameters

options  ParserOptions
The parser options.
stream  Stream
The stream.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

TaskMimeMessage
The parsed message.

Remarks

Loads a MimeMessage from the given stream, using the specified ParserOptions.

Example

C#
                    public static async Task<MimeMessage> LoadMessageAsync (Stream stream, CancellationToken cancellationToken = default)
{
    // Use custom ParserOptions to control how leniently the message is parsed. The
    // ParserOptions.Default instance is used when no options are specified.
    var options = new ParserOptions {
        AddressParserComplianceMode = RfcComplianceMode.Looser,
        MaxMimeDepth = 64
    };

    // LoadAsync() reads the stream asynchronously which makes it ideal for parsing messages
    // directly from a network stream.
    return await MimeMessage.LoadAsync (options, stream, cancellationToken).ConfigureAwait (false);
}
                  

Exceptions

ArgumentNullException

options is .

-or-

stream is .

OperationCanceledException The operation was canceled via the cancellation token.
FormatException There was an error parsing the entity.
IOException An I/O error occurred.

See Also