ISmtp Send Request Interface
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 interface ISmtpSendRequest : ISendRequest- Implements
- ISendRequest
Remarks
A request for sending a message via SMTP.
In addition to the options provided by ISendRequest, 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;
}
}
Properties
| 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 ISendRequest) |
| Recipients |
Get or set the mailbox addresses to use as the envelope recipients.
(Inherited from ISendRequest) |
| Sender |
Get or set the mailbox address to use as the envelope sender.
(Inherited from ISendRequest) |
| TransferProgress |
Get or set the transfer progress reporting mechanism.
(Inherited from ISendRequest) |
Methods
| GetDeliveryStatusNotifications | Get the types of delivery status notification desired for the specified recipient mailbox. |
| OnCompleted |
Called when the server has accepted the message for delivery.
(Inherited from ISendRequest) |
| 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 ISendRequest) |