View on GitHub

MimeKit

A C# MIME creation and parser library with support for S/MIME, PGP and Unix mbox spools.

Download this project as a .zip file Download this project as a tar.gz file

MimeMessage Class

A MIME message.

Syntax

public class MimeMessage

Remarks

A message consists of header fields and, optionally, a body.

The body of the message can either be plain text or it can be a tree of MIME entities such as a text/plain MIME part and a collection of file attachments.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Members

See Also: Inherited members from object.

Public Constructors

Initializes a new instance of the MimeKit.MimeMessage class.
MimeMessage (params object[])
Initializes a new instance of the MimeKit.MimeMessage class.

Public Properties

[read-only]
Attachments IEnumerable<MimePart> . Gets the attachments.
[read-only]
Bcc InternetAddressList . Gets the list of addresses in the Bcc header.
Body MimeEntity . Gets or sets the body of the message.
[read-only]
BodyParts IEnumerable<MimePart> . Gets the body parts of the message.
[read-only]
Cc InternetAddressList . Gets the list of addresses in the Cc header.
Date DateTimeOffset . Gets or sets the date of the message.
[read-only]
From InternetAddressList . Gets the list of addresses in the From header.
[read-only]
Headers HeaderList . Gets the list of headers.
[read-only]
HtmlBody string . Gets the html body of the message if it exists.
InReplyTo string . Gets or sets the Message-Id that this message is in reply to.
MessageId string . Gets or sets the message identifier.
MimeVersion Version . Gets or sets the MIME-Version.
[read-only]
References MessageIdList . Gets or sets the list of references to other messages.
[read-only]
ReplyTo InternetAddressList . Gets the list of addresses in the Reply-To header.
[read-only]
ResentBcc InternetAddressList . Gets the list of addresses in the Resent-Bcc header.
[read-only]
ResentCc InternetAddressList . Gets the list of addresses in the Resent-Cc header.
ResentDate DateTimeOffset . Gets or sets the Resent-Date of the message.
[read-only]
ResentFrom InternetAddressList . Gets the list of addresses in the Resent-From header.
ResentMessageId string . Gets or sets the Resent-Message-Id header.
[read-only]
ResentReplyTo InternetAddressList . Gets the list of addresses in the Resent-Reply-To header.
ResentSender MailboxAddress . Gets or sets the address in the Resent-Sender header.
[read-only]
ResentTo InternetAddressList . Gets the list of addresses in the Resent-To header.
Sender MailboxAddress . Gets or sets the address in the Sender header.
Subject string . Gets or sets the subject of the message.
[read-only]
TextBody string . Gets the text body of the message if it exists.
[read-only]
To InternetAddressList . Gets the list of addresses in the To header.

Public Methods

static
CreateFromMailMessage (System.Net.Mail.MailMessage) : MimeMessage
Creates a new MimeKit.MimeMessage from a System.Net.Mail.MailMessage.
Encrypt (MimeKit.Cryptography.CryptographyContext)
Encrypt the message to the sender and all of the recipients using the specified cryptography context.
static
Load (System.IO.Stream, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified stream.
static
Load (string, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified file.
static
Load (ParserOptions, System.IO.Stream, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified stream.
static
Load (ParserOptions, string, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified file.
static
Load (System.IO.Stream, bool, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified stream.
static
Load (ParserOptions, System.IO.Stream, bool, System.Threading.CancellationToken) : MimeMessage
Load a MimeKit.MimeMessage from the specified stream.
Sign (MimeKit.Cryptography.CryptographyContext)
Sign the message using the specified cryptography context and the SHA-1 digest algorithm.
Sign (MimeKit.Cryptography.CryptographyContext, MimeKit.Cryptography.DigestAlgorithm)
Sign the message using the specified cryptography context and digest algorithm.
SignAndEncrypt (MimeKit.Cryptography.CryptographyContext)
Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the SHA-1 digest algorithm.
SignAndEncrypt (MimeKit.Cryptography.CryptographyContext, MimeKit.Cryptography.DigestAlgorithm)
Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the specified digest algorithm.
override
ToString () : string
Returns a string that represents the current MimeKit.MimeMessage.
WriteTo (System.IO.Stream, System.Threading.CancellationToken)
Writes the message to the specified output stream.
WriteTo (string, System.Threading.CancellationToken)
Writes the message to the specified file.
WriteTo (FormatOptions, System.IO.Stream, System.Threading.CancellationToken)
Writes the message to the specified output stream.
WriteTo (FormatOptions, string, System.Threading.CancellationToken)
Writes the message to the specified file.

Public Operators

static
Conversion to MimeKit.MimeMessage (Explicit) Explicit cast to convert a System.Net.Mail.MailMessage to a MimeKit.MimeMessage.

Member Details

MimeMessage Constructor

Initializes a new instance of the MimeKit.MimeMessage class.

Syntax

public MimeMessage ()

Remarks

Creates a new MIME message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

MimeMessage Constructor

Initializes a new instance of the MimeKit.MimeMessage class.

Syntax

public MimeMessage (params object[] args)

Parameters

args
An array of initialization parameters: headers and message parts.

Exceptions

Type Reason
ArgumentNullException args is null.
ArgumentException

args contains more than one MimeKit.MimeEntity.

-or-

args contains one or more arguments of an unknown type.

Remarks

Creates a new MimeKit.MimeMessage.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Attachments Property

Gets the attachments.

Syntax

public IEnumerable<MimePart> Attachments { get; }

Value

The attachments.

Remarks

Traverses over the MIME tree, enumerating all of the MimeKit.MimePart objects that have a Content-Disposition header set to "attachment".

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Bcc Property

Gets the list of addresses in the Bcc header.

Syntax

public InternetAddressList Bcc { get; }

Value

The list of addresses in the Bcc header.

Remarks

Recipients in the Blind-Carpbon-Copy list will not be visible to the other recipients of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Body Property

Gets or sets the body of the message.

Syntax

public MimeEntity Body { get; set; }

Value

The body of the message.

Remarks

The body of the message can either be plain text or it can be a tree of MIME entities such as a text/plain MIME part and a collection of file attachments.

For a convenient way of constructing message bodies, see the MimeKit.BodyBuilder class.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

BodyParts Property

Gets the body parts of the message.

Syntax

public IEnumerable<MimePart> BodyParts { get; }

Value

The body parts.

Remarks

Traverses over the MIME tree, enumerating all of the MimeKit.MimePart objects.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Cc Property

Gets the list of addresses in the Cc header.

Syntax

public InternetAddressList Cc { get; }

Value

The list of addresses in the Cc header.

Remarks

The addresses in the Cc header are secondary recipients of the message and are usually not the individuals being directly addressed in the content of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

CreateFromMailMessage Method

Syntax

public static MimeMessage CreateFromMailMessage (System.Net.Mail.MailMessage message)

Parameters

message
The message.

Returns

The equivalent MimeKit.MimeMessage.

Exceptions

Type Reason
ArgumentNullException message is null.

Remarks

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Date Property

Gets or sets the date of the message.

Syntax

public DateTimeOffset Date { get; set; }

Value

The date of the message.

Remarks

If the date is not explicitly set before the message is written to a stream, the date will default to the exact moment when it is written to said stream.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Encrypt Method

Encrypt the message to the sender and all of the recipients using the specified cryptography context.

Syntax

Parameters

ctx
The cryptography context.

Exceptions

Type Reason
ArgumentNullException ctx is null.
ArgumentException An unknown type of cryptography context was used.
InvalidOperationException

The MimeMessage.Body has not been set.

-or-

No recipients have been specified.

MimeKit.Cryptography.CertificateNotFoundException A certificate could not be found for one or more of the recipients.
MimeKit.Cryptography.PublicKeyNotFoundException The public key could not be found for one or more of the recipients.

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be encrypted to all of the addresses specified in the Resent headers (Resent-Sender, Resent-From, Resent-To, Resent-Cc, and Resent-Bcc), otherwise the message will be encrypted to all of the addresses specified in the standard address headers (Sender, From, To, Cc, and Bcc).

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

From Property

Gets the list of addresses in the From header.

Syntax

public InternetAddressList From { get; }

Value

The list of addresses in the From header.

Remarks

The "From" header specifies the author(s) of the message.

If more than one MimeKit.MailboxAddress is added to the list of "From" addresses, the MimeMessage.Sender should be set to the single MimeKit.MailboxAddress of the personal actually sending the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Headers Property

Gets the list of headers.

Syntax

public HeaderList Headers { get; }

Value

The list of headers.

Remarks

Represents the list of headers for a message. Typically, the headers of a message will contain transmission headers such as From and To along with metadata headers such as Subject and Date, but may include just about anything.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

HtmlBody Property

Gets the html body of the message if it exists.

Syntax

public string HtmlBody { get; }

Value

The html body if it exists; otherwise, null.

Remarks

Gets the HTML-formatted body of the message if it exists.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

InReplyTo Property

Gets or sets the Message-Id that this message is in reply to.

Syntax

public string InReplyTo { get; set; }

Value

The message id that this message is in reply to.

Exceptions

Type Reason
ArgumentException value is improperly formatted.

Remarks

If the message is a reply to another message, it will typically use the In-Reply-To header to specify the Message-Id of the original message being replied to.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified stream.

Syntax

public static MimeMessage Load (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken)

Parameters

stream
The stream.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException stream is null.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.IOException An I/O error occurred.
FormatException There was an error parsing the entity.

Remarks

Loads a MimeKit.MimeMessage from the given stream, using the default MimeKit.ParserOptions.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified file.

Syntax

public static MimeMessage Load (string fileName, System.Threading.CancellationToken cancellationToken)

Parameters

fileName
The name of the file to load.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException fileName is null.
ArgumentException fileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.
System.IO.FileNotFoundException The specified file path could not be found.
UnauthorizedAccessException The user does not have access to read the specified file.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.IOException An I/O error occurred.
FormatException There was an error parsing the entity.
System.IO.DirectoryNotFoundException fileName is an invalid file path.

Remarks

Loads a MimeKit.MimeMessage from the file at the given path, using the default MimeKit.ParserOptions.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified stream.

Syntax

public static MimeMessage Load (ParserOptions options, System.IO.Stream stream, System.Threading.CancellationToken cancellationToken)

Parameters

options
The parser options.
stream
The stream.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException

options is null.

-or-

stream is null.

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

Remarks

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

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified file.

Syntax

public static MimeMessage Load (ParserOptions options, string fileName, System.Threading.CancellationToken cancellationToken)

Parameters

options
The parser options.
fileName
The name of the file to load.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException

options is null.

-or-

fileName is null.

ArgumentException fileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.
System.IO.FileNotFoundException The specified file path could not be found.
UnauthorizedAccessException The user does not have access to read the specified file.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.IOException An I/O error occurred.
FormatException There was an error parsing the entity.
System.IO.DirectoryNotFoundException fileName is an invalid file path.

Remarks

Loads a MimeKit.MimeMessage from the file at the given path, using the specified MimeKit.ParserOptions.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified stream.

Syntax

public static MimeMessage Load (System.IO.Stream stream, bool persistent, System.Threading.CancellationToken cancellationToken)

Parameters

stream
The stream.
persistent
true if the stream is persistent; otherwise false.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException stream is null.
OperationCanceledException The operation was canceled via the cancellation token.
FormatException There was an error parsing the entity.
System.IO.IOException An I/O error occurred.

Remarks

Loads a MimeKit.MimeMessage from the given stream, using the default MimeKit.ParserOptions.

If persistent is true and stream is seekable, then the MimeKit.MimeParser will not copy the content of MimeKit.MimeParts into memory. Instead, it will use a MimeKit.IO.BoundStream to reference a substream of stream. This has the potential to not only save mmeory usage, but also improve MimeKit.MimeParser performance.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Load Method

Load a MimeKit.MimeMessage from the specified stream.

Syntax

public static MimeMessage Load (ParserOptions options, System.IO.Stream stream, bool persistent, System.Threading.CancellationToken cancellationToken)

Parameters

options
The parser options.
stream
The stream.
persistent
true if the stream is persistent; otherwise false.
cancellationToken
A cancellation token.

Returns

The parsed message.

Exceptions

Type Reason
ArgumentNullException

options is null.

-or-

stream is null.

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

Remarks

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

If persistent is true and stream is seekable, then the MimeKit.MimeParser will not copy the content of MimeKit.MimeParts into memory. Instead, it will use a MimeKit.IO.BoundStream to reference a substream of stream. This has the potential to not only save mmeory usage, but also improve MimeKit.MimeParser performance.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

MessageId Property

Gets or sets the message identifier.

Syntax

public string MessageId { get; set; }

Value

The message identifier.

Exceptions

Type Reason
ArgumentNullException value is null.
ArgumentException value is improperly formatted.

Remarks

The Message-Id is meant to be a globally unique identifier for a message.

MimeKit.Utils.MimeUtils.GenerateMessageId can be used to generate this value.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

MimeVersion Property

Gets or sets the MIME-Version.

Syntax

public Version MimeVersion { get; set; }

Value

The MIME version.

Exceptions

Type Reason
ArgumentNullException value is null.

Remarks

The MIME-Version header specifies the version of the MIME specification that the message was created for.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Explicit cast to convert a System.Net.Mail.MailMessage to a MimeKit.MimeMessage.

Syntax

public static explicit operator MimeMessage (System.Net.Mail.MailMessage message)

Parameters

message
The message.

Returns

The equivalent MimeKit.MimeMessage.

Remarks

Allows creation of messages using Microsoft's System.Net.Mail APIs.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

References Property

Gets or sets the list of references to other messages.

Syntax

public MessageIdList References { get; }

Value

The references.

Remarks

The References header contains a chain of Message-Ids back to the original message that started the thread.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ReplyTo Property

Gets the list of addresses in the Reply-To header.

Syntax

public InternetAddressList ReplyTo { get; }

Value

The list of addresses in the Reply-To header.

Remarks

When the list of addresses in the Reply-To header is not empty, it contains the address(es) where the author(s) of the message prefer that replies be sent.

When the list of addresses in the Reply-To header is empty, replies should be sent to the mailbox(es) specified in the From header.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentBcc Property

Gets the list of addresses in the Resent-Bcc header.

Syntax

public InternetAddressList ResentBcc { get; }

Value

The list of addresses in the Resent-Bcc header.

Remarks

Recipients in the Resent-Bcc list will not be visible to the other recipients of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentCc Property

Gets the list of addresses in the Resent-Cc header.

Syntax

public InternetAddressList ResentCc { get; }

Value

The list of addresses in the Resent-Cc header.

Remarks

The addresses in the Resent-Cc header are secondary recipients of the message and are usually not the individuals being directly addressed in the content of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentDate Property

Gets or sets the Resent-Date of the message.

Syntax

public DateTimeOffset ResentDate { get; set; }

Value

The Resent-Date of the message.

Remarks

Gets or sets the Resent-Date of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentFrom Property

Gets the list of addresses in the Resent-From header.

Syntax

public InternetAddressList ResentFrom { get; }

Value

The list of addresses in the Resent-From header.

Remarks

The "Resent-From" header specifies the author(s) of the messagebeing resent.

If more than one MimeKit.MailboxAddress is added to the list of "Resent-From" addresses, the MimeMessage.ResentSender should be set to the single MimeKit.MailboxAddress of the personal actually sending the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentMessageId Property

Gets or sets the Resent-Message-Id header.

Syntax

public string ResentMessageId { get; set; }

Value

The Resent-Message-Id.

Exceptions

Type Reason
ArgumentNullException value is null.
ArgumentException value is improperly formatted.

Remarks

The Resent-Message-Id is meant to be a globally unique identifier for a message.

MimeKit.Utils.MimeUtils.GenerateMessageId can be used to generate this value.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentReplyTo Property

Gets the list of addresses in the Resent-Reply-To header.

Syntax

public InternetAddressList ResentReplyTo { get; }

Value

The list of addresses in the Resent-Reply-To header.

Remarks

When the list of addresses in the Resent-Reply-To header is not empty, it contains the address(es) where the author(s) of the resent message prefer that replies be sent.

When the list of addresses in the Resent-Reply-To header is empty, replies should be sent to the mailbox(es) specified in the Resent-From header.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentSender Property

Gets or sets the address in the Resent-Sender header.

Syntax

public MailboxAddress ResentSender { get; set; }

Value

The address in the Resent-Sender header.

Remarks

The resent sender may differ from the addresses in MimeMessage.ResentFrom if the message was sent by someone on behalf of someone else.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ResentTo Property

Gets the list of addresses in the Resent-To header.

Syntax

public InternetAddressList ResentTo { get; }

Value

The list of addresses in the Resent-To header.

Remarks

The addresses in the Resent-To header are the primary recipients of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Sender Property

Gets or sets the address in the Sender header.

Syntax

public MailboxAddress Sender { get; set; }

Value

The address in the Sender header.

Remarks

The sender may differ from the addresses in MimeMessage.From if the message was sent by someone on behalf of someone else.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Sign Method

Sign the message using the specified cryptography context and the SHA-1 digest algorithm.

Syntax

Parameters

ctx
The cryptography context.

Exceptions

Type Reason
ArgumentNullException ctx is null.
InvalidOperationException

The MimeMessage.Body has not been set.

-or-

A sender has not been specified.

MimeKit.Cryptography.CertificateNotFoundException A signing certificate could not be found for the sender.
MimeKit.Cryptography.PrivateKeyNotFoundException The private key could not be found for the sender.

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be signed using the Resent-Sender (or first mailbox in the Resent-From) address as the signer address, otherwise the Sender or From address will be used instead.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Sign Method

Sign the message using the specified cryptography context and digest algorithm.

Syntax

Parameters

ctx
The cryptography context.
digestAlgo
The digest algorithm.

Exceptions

Type Reason
ArgumentNullException ctx is null.
InvalidOperationException

The MimeMessage.Body has not been set.

-or-

A sender has not been specified.

ArgumentOutOfRangeException The digestAlgo was out of range.
NotSupportedException The digestAlgo is not supported.
MimeKit.Cryptography.CertificateNotFoundException A signing certificate could not be found for the sender.
MimeKit.Cryptography.PrivateKeyNotFoundException The private key could not be found for the sender.

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be signed using the Resent-Sender (or first mailbox in the Resent-From) address as the signer address, otherwise the Sender or From address will be used instead.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

SignAndEncrypt Method

Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the SHA-1 digest algorithm.

Syntax

Parameters

ctx
The cryptography context.

Exceptions

Type Reason
ArgumentNullException ctx is null.
ArgumentException An unknown type of cryptography context was used.
InvalidOperationException

The MimeMessage.Body has not been set.

-or-

The sender has been specified.

-or-

No recipients have been specified.

MimeKit.Cryptography.CertificateNotFoundException A certificate could not be found for the signer or one or more of the recipients.
MimeKit.Cryptography.PrivateKeyNotFoundException The private key could not be found for the sender.
MimeKit.Cryptography.PublicKeyNotFoundException The public key could not be found for one or more of the recipients.

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be signed using the Resent-Sender (or first mailbox in the Resent-From) address as the signer address, otherwise the Sender or From address will be used instead.

Likewise, if either of the Resent-Sender or Resent-From headers are set, then the message will be encrypted to all of the addresses specified in the Resent headers (Resent-Sender, Resent-From, Resent-To, Resent-Cc, and Resent-Bcc), otherwise the message will be encrypted to all of the addresses specified in the standard address headers (Sender, From, To, Cc, and Bcc).

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

SignAndEncrypt Method

Sign and encrypt the message to the sender and all of the recipients using the specified cryptography context and the specified digest algorithm.

Syntax

Parameters

ctx
The cryptography context.
digestAlgo
The digest algorithm.

Exceptions

Type Reason
ArgumentNullException ctx is null.
ArgumentException An unknown type of cryptography context was used.
ArgumentOutOfRangeException The digestAlgo was out of range.
InvalidOperationException

The MimeMessage.Body has not been set.

-or-

The sender has been specified.

-or-

No recipients have been specified.

NotSupportedException The digestAlgo is not supported.
MimeKit.Cryptography.CertificateNotFoundException A certificate could not be found for the signer or one or more of the recipients.
MimeKit.Cryptography.PrivateKeyNotFoundException The private key could not be found for the sender.
MimeKit.Cryptography.PublicKeyNotFoundException The public key could not be found for one or more of the recipients.

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be signed using the Resent-Sender (or first mailbox in the Resent-From) address as the signer address, otherwise the Sender or From address will be used instead.

Likewise, if either of the Resent-Sender or Resent-From headers are set, then the message will be encrypted to all of the addresses specified in the Resent headers (Resent-Sender, Resent-From, Resent-To, Resent-Cc, and Resent-Bcc), otherwise the message will be encrypted to all of the addresses specified in the standard address headers (Sender, From, To, Cc, and Bcc).

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

Subject Property

Gets or sets the subject of the message.

Syntax

public string Subject { get; set; }

Value

The subject of the message.

Exceptions

Type Reason
ArgumentNullException value is null.

Remarks

The Subject is typically a short string denoting the topic of the message.

Replies will often use "Re: " followed by the Subject of the original message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

TextBody Property

Gets the text body of the message if it exists.

Syntax

public string TextBody { get; }

Value

The text body if it exists; otherwise, null.

Remarks

Gets the text content of the first text/plain body part that is found (in depth-first search order) which is not an attachment.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

To Property

Gets the list of addresses in the To header.

Syntax

public InternetAddressList To { get; }

Value

The list of addresses in the To header.

Remarks

The addresses in the To header are the primary recipients of the message.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

ToString Method

Returns a string that represents the current MimeKit.MimeMessage.

Syntax

public override string ToString ()

Returns

A string that represents the current MimeKit.MimeMessage.

Remarks

Returns a string that represents the current MimeKit.MimeMessage.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

WriteTo Method

Writes the message to the specified output stream.

Syntax

public void WriteTo (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken)

Parameters

stream
The output stream.
cancellationToken
A cancellation token.

Exceptions

Type Reason
ArgumentNullException stream is null.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.IOException An I/O error occurred.

Remarks

Writes the message to the output stream using the default formatting options.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

WriteTo Method

Writes the message to the specified file.

Syntax

public void WriteTo (string fileName, System.Threading.CancellationToken cancellationToken)

Parameters

fileName
The file.
cancellationToken
A cancellation token.

Exceptions

Type Reason
ArgumentNullException fileName is null.
ArgumentException fileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.DirectoryNotFoundException fileName is an invalid file path.
System.IO.FileNotFoundException The specified file path could not be found.
UnauthorizedAccessException The user does not have access to write to the specified file.
System.IO.IOException An I/O error occurred.

Remarks

Writes the message to the specified file using the default formatting options.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

WriteTo Method

Writes the message to the specified output stream.

Syntax

public void WriteTo (FormatOptions options, System.IO.Stream stream, System.Threading.CancellationToken cancellationToken)

Parameters

options
The formatting options.
stream
The output stream.
cancellationToken
A cancellation token.

Exceptions

Type Reason
ArgumentNullException

options is null.

-or-

stream is null.

OperationCanceledException The operation was canceled via the cancellation token.
System.IO.IOException An I/O error occurred.

Remarks

Writes the message to the output stream using the provided formatting options.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0

WriteTo Method

Writes the message to the specified file.

Syntax

public void WriteTo (FormatOptions options, string fileName, System.Threading.CancellationToken cancellationToken)

Parameters

options
The formatting options.
fileName
The file.
cancellationToken
A cancellation token.

Exceptions

Type Reason
ArgumentNullException

options is null.

-or-

fileName is null.

ArgumentException fileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.
OperationCanceledException The operation was canceled via the cancellation token.
System.IO.DirectoryNotFoundException fileName is an invalid file path.
System.IO.FileNotFoundException The specified file path could not be found.
UnauthorizedAccessException The user does not have access to write to the specified file.
System.IO.IOException An I/O error occurred.

Remarks

Writes the message to the specified file using the provided formatting options.

Requirements

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll)
Assembly Versions: 1.0.0.0