DeliveryStatusNotification Enumeration

Delivery status notification types.

Definition

Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
[FlagsAttribute]
public enum DeliveryStatusNotification

Remarks

A set of flags that may be bitwise-or'd together to specify when a delivery status notification should be sent for a particular recipient.

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;
    }
}
                  

Members

Never 0 Never send delivery status notifications.
Success 1 Send a notification on successful delivery to the recipient.
Failure 2 Send a notification on failure to deliver to the recipient.
Delay 4 Send a notification when the delivery to the recipient has been delayed for an unusual amount of time.

See Also

Reference