How to check if an email was delivered using MailKit

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Make sure that your SMTP server supports the DSN extension.

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x