0

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?

Bedir
  • 476
  • 1
  • 6
  • 17

1 Answers1

1

Make sure that your SMTP server supports the DSN extension.

var supportsDsn = client.Capabilities.HasFlag (SmtpCapabilities.Dsn);
jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • The Boolean flag was set to false. I am using "smtp.gmail.com" as my SMTP server to test my API. Is this just something I have to configure in my server? Big fan of your work btw – Bedir Dec 02 '20 at 14:57
  • 1
    I just checked and it seems that GMail does not support the DSN extension which explains why it's not working for you. So yea, when you configure an SMTP server for production, you'll need to make sure that it supports this (which may involve configuration depending on the server software). – jstedfast Dec 02 '20 at 15:02
  • I am now receiving emails with delivery status notifications. I was just wondering if there was any other way, besides relying on receiving DSN emails, to know if an email was delivered or not. – Bedir Dec 15 '20 at 17:20
  • 1
    Unfortunately there isn’t. DSNs are the only way that I know of to do this. – jstedfast Dec 15 '20 at 17:22
  • Have a similar problem when sending through mandrill. It seems to go through, but nothing in mandrill logs, nor my inbox (test msg). – Daniel Mošmondor Jul 09 '22 at 19:32