Smtp Send Request Class
A request for sending a message via SMTP.
Definition
Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public class SmtpSendRequest : SendRequest,
ISmtpSendRequest, ISendRequest- Inheritance
- Object SendRequest SmtpSendRequest
- Implements
- ISendRequest, ISmtpSendRequest
Remarks
A request for sending a message via SMTP.
In addition to the options provided by SendRequest, an SMTP send request can specify Delivery Status Notification options and can be notified as the SMTP server accepts or rejects the sender and each of the recipients.
Example
C#
public static void SendWithDeliveryStatusNotifications (MimeMessage message)
{
var request = new SmtpSendRequest (message) {
// Since you will want to be able to map the envelope identifier back to the
// message, the obvious identifier to use is probably the Message-Id value.
EnvelopeId = message.MessageId,
// Request that the server include only the headers of the original message
// in any delivery status notifications that it sends back.
DeliveryStatusNotificationType = DeliveryStatusNotificationType.HeadersOnly,
// In this example, we only want to be notified of failures to deliver to a mailbox.
// If you also want to be notified of delays or successful deliveries, simply bitwise-or
// whatever combination of flags you want to be notified about.
DeliveryStatusNotifications = DeliveryStatusNotification.Failure
};
using (var client = new SmtpClient ()) {
client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
var result = (SmtpSendResult) client.Send (request);
Console.WriteLine ($"The server responded with: {result.StatusCode} {result.ResponseText}");
client.Disconnect (true);
}
}
public class PerRecipientSmtpSendRequest : SmtpSendRequest
{
public PerRecipientSmtpSendRequest (MimeMessage message) : base (message)
{
EnvelopeId = message.MessageId;
}
/// <summary>
/// Get the types of delivery status notification desired for the specified recipient mailbox.
/// </summary>
/// <remarks>
/// Gets the types of delivery status notification desired for the specified recipient mailbox.
/// </remarks>
/// <returns>The desired delivery status notification type.</returns>
/// <param name="recipient">The recipient mailbox.</param>
public override DeliveryStatusNotification? GetDeliveryStatusNotifications (MailboxAddress recipient)
{
// Only request delivery status notifications for recipients outside of our domain.
if (recipient.Domain.Equals ("example.com", StringComparison.OrdinalIgnoreCase))
return DeliveryStatusNotification.Never;
return DeliveryStatusNotification.Failure | DeliveryStatusNotification.Delay;
}
}
Constructors
| SmtpSendRequest(MimeMessage) | Initializes a new instance of the SmtpSendRequest class. |
| SmtpSendRequest(MimeMessage, MailboxAddress, IEnumerableMailboxAddress) | Initializes a new instance of the SmtpSendRequest class. |
Properties
| DeliveryStatusNotifications | Get or set the types of delivery status notification desired for each of the recipients. |
| DeliveryStatusNotificationType | Get or set how much of the message to include in any failed delivery status notifications. |
| EnvelopeId | Get or set the envelope identifier to be used with delivery status notifications. |
| Message |
Get the message that should be sent.
(Inherited from SendRequest) |
| Recipients |
Get or set the mailbox addresses to use as the envelope recipients.
(Inherited from SendRequest) |
| Sender |
Get or set the mailbox address to use as the envelope sender.
(Inherited from SendRequest) |
| TransferProgress |
Get or set the transfer progress reporting mechanism.
(Inherited from SendRequest) |
Methods
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
| GetDeliveryStatusNotifications | Get the types of delivery status notification desired for the specified recipient mailbox. |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
| OnCompleted |
Called when the server has accepted the message for delivery.
(Inherited from SendRequest) |
| OnNoRecipientsAccepted | Called when none of the recipients were accepted by the SMTP server. |
| OnRecipientAccepted | Called when a recipient is accepted by the SMTP server. |
| OnRecipientNotAccepted | Called when a recipient is not accepted by the SMTP server. |
| OnSenderAccepted | Called when the sender is accepted by the SMTP server. |
| OnSenderNotAccepted | Called when the sender is not accepted by the SMTP server. |
| OnStarted |
Called when the message is about to be sent to the server.
(Inherited from SendRequest) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |