0
votes

I am using @jstedfast Mimekit/Mailkit library to send emails from my API. I want to know how to get the delivery status of each email. I tried overriding DeliveryStatusNotification to send notifications on Success:

public class DSNSmtpClient : SmtpClient
{
    public DSNSmtpClient()
    {
    }
    protected override string GetEnvelopeId(MimeMessage message)
    {
        return message.MessageId;
    }
    protected override DeliveryStatusNotification? GetDeliveryStatusNotifications(MimeMessage message, MailboxAddress mailbox)
    {
        return DeliveryStatusNotification.Success;
    }
}

I am able to send emails like this:

using (DSNSmtpClient dsnSmtpClient = new DSNSmtpClient())
{
    dsnSmtpClient.Connect(_emailCredentials.Value.SmtpServer, _emailCredentials.Value.Port, true);
    dsnSmtpClient.Authenticate(_emailCredentials.Value.UserName, _emailCredentials.Value.Password);
    dsnSmtpClient.Send(mimeMessage);
    dsnSmtpClient.Disconnect(true);
}

But I do not get any emails regarding delivery status(or anything) in my sender inbox.

I found some related links:

get the delivery status of email with mimekit/mailkit library

https://github.com/jstedfast/MailKit/issues/602

But they only got me this far. What else do I need to do to see if an email was delivered or not?

1

1 Answers

1
votes

Make sure that your SMTP server supports the DSN extension.

var supportsDsn = client.Capabilities.HasFlag (SmtpCapabilities.Dsn);