Click or drag to resize
MimeKit

MailTransportSend Method (MimeMessage, CancellationToken, ITransferProgress)

Send the specified message.

Namespace:  MailKit
Assembly:  MailKit (in MailKit.dll) Version: 2.3.0
Syntax
C#
public virtual void Send(
	MimeMessage message,
	CancellationToken cancellationToken = null,
	ITransferProgress progress = null
)

Parameters

message
Type: MimeKitMimeMessage
The message.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
The cancellation token.
progress (Optional)
Type: MailKitITransferProgress
The progress reporting mechanism.

Implements

IMailTransportSend(MimeMessage, CancellationToken, ITransferProgress)
Exceptions
ExceptionCondition
ArgumentNullExceptionmessage is null.
ObjectDisposedException The MailTransport has been disposed.
ServiceNotConnectedException The MailTransport is not connected.
ServiceNotAuthenticatedException Authentication is required before sending a message.
InvalidOperationException

A sender has not been specified.

-or-

No recipients have been specified.

OperationCanceledException The operation has been canceled.
IOException An I/O error occurred.
CommandException The send command failed.
ProtocolException A protocol exception occurred.
Remarks

Sends the specified message.

The sender address is determined by checking the following message headers (in order of precedence): Resent-Sender, Resent-From, Sender, and From.

If either the Resent-Sender or Resent-From addresses are present, the recipients are collected from the Resent-To, Resent-Cc, and Resent-Bcc headers, otherwise the To, Cc, and Bcc headers are used.

Examples
C#
public static void SendMessage (MimeMessage message)
{
    using (var client = new SmtpClient ()) {
        client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);

        client.Authenticate ("username", "password");

        client.Send (message);

        client.Disconnect (true);
    }
}
See Also