'Sending email with SMTP, don't receive Delivery Notifications for On Failure
I need to setup my company's "no reply" email account to receive notifications when an email fails to send.
I send emails using the System.Net.Mail.SmtpClient all the time. I use my own work email address for testing. But for production use, my company has a "no reply" account. Our "no reply" account also has a legitimate AD User account and inbox we use for monitoring purposes. No different in practice than my own account.
When testing with my work address, I get the DeliveryNotifications for OnSuccess and OnFailure.
When using the "no reply" address, I get the DeliveryNotification for OnSuccess, but it never gives me one for OnFailure.
Which is a problem because the OnFailure notifications are the only ones we care about. I just ran it with OnSuccess options for testing purposes. When using my work email, when I intentionally send an email to an invalid address, I receive the failure notification. The only thing I changed was the credentials to the production "noreply" address, and when I run the same tests, I get the success notifications just fine. But when I test with a bad address to get a failure, I receive nothing. Even though I got both on my own account.
Here's (the important bits of) my code:
using (SmtpClient client = new SmtpClient("mail.mycompany.com"))
{
//I do the credentials thing here first...
//build email
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]", "No Reply");
mailMessage.To.Add(new MailAddress("[email protected]"));
mailMessage.Subject = "Test";
mailMessage.Body = "Test";
//notify on failure
mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
//send
client.Send(mailMessage);
}
I've tried using other API's like the Exchange Services. But I can't even get those to authenticate and send a successful test using my own credentials, let alone "no reply"'s. Using SMTP, I can at least get an email out at all. I'm wondering if the issue may lie elsewhere and not necessarily with my code. Especially since it works in all other scenarios except for the one that matters. I'm just out of ideas.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
