SmtpClient.SendMailAsync Method

Definition

Sends the specified message to an SMTP server for delivery as an asynchronous operation.

Overloads

SendMailAsync(MailMessage)

Sends the specified message to an SMTP server for delivery as an asynchronous operation.

SendMailAsync(MailMessage, CancellationToken)

Sends the specified message to an SMTP server for delivery as an asynchronous operation.

SendMailAsync(String, String, String, String)

Sends the specified message to an SMTP server for delivery as an asynchronous operation. The message sender, recipients, subject, and message body are specified using String objects.

SendMailAsync(String, String, String, String, CancellationToken)

Sends the specified message to an SMTP server for delivery as an asynchronous operation, using the specified sender, recipients, subject, and body strings.

SendMailAsync(MailMessage)

Sends the specified message to an SMTP server for delivery as an asynchronous operation.

public:
 System::Threading::Tasks::Task ^ SendMailAsync(System::Net::Mail::MailMessage ^ message);
public System.Threading.Tasks.Task SendMailAsync (System.Net.Mail.MailMessage message);
member this.SendMailAsync : System.Net.Mail.MailMessage -> System.Threading.Tasks.Task
Public Function SendMailAsync (message As MailMessage) As Task

Parameters

message
MailMessage

A MailMessage that contains the message to send.

Returns

Task

The task object representing the asynchronous operation.

Exceptions

message is null.

Remarks

This operation will not block. The returned Task object will complete once the message has been sent.

Applies to

SendMailAsync(MailMessage, CancellationToken)

Sends the specified message to an SMTP server for delivery as an asynchronous operation.

public:
 System::Threading::Tasks::Task ^ SendMailAsync(System::Net::Mail::MailMessage ^ message, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task SendMailAsync (System.Net.Mail.MailMessage message, System.Threading.CancellationToken cancellationToken);
member this.SendMailAsync : System.Net.Mail.MailMessage * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SendMailAsync (message As MailMessage, cancellationToken As CancellationToken) As Task

Parameters

message
MailMessage

The message to send.

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

Task

The task object representing the asynchronous operation.

Exceptions

message is null.

Remarks

This operation will not block. The returned Task object will complete once the message has been sent.

Applies to

SendMailAsync(String, String, String, String)

Sends the specified message to an SMTP server for delivery as an asynchronous operation. The message sender, recipients, subject, and message body are specified using String objects.

public:
 System::Threading::Tasks::Task ^ SendMailAsync(System::String ^ from, System::String ^ recipients, System::String ^ subject, System::String ^ body);
public System.Threading.Tasks.Task SendMailAsync (string from, string recipients, string? subject, string? body);
public System.Threading.Tasks.Task SendMailAsync (string from, string recipients, string subject, string body);
member this.SendMailAsync : string * string * string * string -> System.Threading.Tasks.Task
Public Function SendMailAsync (from As String, recipients As String, subject As String, body As String) As Task

Parameters

from
String

A String that contains the address information of the message sender.

recipients
String

A String that contains the addresses that the message is sent to.

subject
String

A String that contains the subject line for the message.

body
String

A String that contains the message body.

Returns

Task

The task object representing the asynchronous operation.

Exceptions

from is null.

-or-

recipients is null.

from is Empty.

-or-

recipients is Empty.

Remarks

This operation will not block. The returned Task object will complete once the message has been sent.

Applies to

SendMailAsync(String, String, String, String, CancellationToken)

Sends the specified message to an SMTP server for delivery as an asynchronous operation, using the specified sender, recipients, subject, and body strings.

public:
 System::Threading::Tasks::Task ^ SendMailAsync(System::String ^ from, System::String ^ recipients, System::String ^ subject, System::String ^ body, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task SendMailAsync (string from, string recipients, string? subject, string? body, System.Threading.CancellationToken cancellationToken);
member this.SendMailAsync : string * string * string * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SendMailAsync (from As String, recipients As String, subject As String, body As String, cancellationToken As CancellationToken) As Task

Parameters

from
String

The address information of the message sender.

recipients
String

The addresses that the message is sent to.

subject
String

The subject line for the message.

body
String

The message body.

cancellationToken
CancellationToken

The cancellation token to cancel the operation.

Returns

Task

The task object representing the asynchronous operation.

Exceptions

from is null.

-or-

recipients is null.

from is Empty.

-or-

recipients is Empty.

Remarks

This operation will not block. The returned Task object will complete once the message has been sent.

Applies to