Mail TransportSend(Format Options, ISend Request, Cancellation Token) Method
Send a message.
Definition
Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
The result of sending the message.
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public abstract SendResult Send(
FormatOptions options,
ISendRequest request,
CancellationToken cancellationToken = default
)Parameters
- options FormatOptions
- The formatting options.
- request ISendRequest
- The send request.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
SendResultThe result of sending the message.
Implements
IMailTransportSend(FormatOptions, ISendRequest, CancellationToken)Remarks
Sends a message as specified by the request.
If the request does not specify a Sender, the sender address is determined by checking the following message headers (in order of precedence): Resent-Sender, Resent-From, Sender, and From.
If the request does not specify any Recipients and 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.
Example
C#
public static void SendMessageWithOptions (MimeMessage message)
{
using (var client = new SmtpClient ()) {
client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
var options = FormatOptions.Default.Clone ();
if (client.Capabilities.Contains (SmtpCapability.UTF8))
options.International = true;
client.Send (options, message);
client.Disconnect (true);
}
}
Exceptions
| ArgumentNullException |
options is . -or- request is . |
| 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. |