0

Read multiple posts about .net mail delivery notifications and tested multiple things:

Though I'm still stuck. What I want to accomplish is the following: I only want to know if the email-address which the mail is send to is valid, and not valid as in a valid format but valid as in: does the email address exist.

Sometimes a user will send an email to an address but by accident types 1 letter wrong, the mail is valid since it contains a domain and @ but the mail address doesn't exist. The sender will think it has been send correctly since they didn't receive any notification.

I want to make sure the sender gets the undelivered notification.

When using code to send mails through Outlook for example you automatically get a undelivered message if the mail address doesn't exists, however with SMTP (I am) not so lucky. I tried it with this bit of code:

 using (var msg = new MailMessage())
 using (var client = new SmtpClient("spamfilter.mySpamFilter.com", 587))
        {

           msg.IsBodyHtml = true;
           msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

           msg.From = new MailAddress(FromAddress);

           msg.To.Add(TO);

           msg.Body = Body;
           msg.Subject = Subject;

           //Send mail
           try
           {
               client.Send(msg);
           }
           catch (SmtpFailedRecipientsException ex)
           {

               throw ex;
           }
        }

For the To address I created an address that is 100% invalid. Though, the exception is never reached.

Can the spamfilter be the problem? For example, when I check the spamfilter I can see the messages have the refused send status for the invalid email addresses but the action status is allowed (so no spam). So it looks like the spamfilter never returns the exception back to the code.

Or is it just not possible what I want to achieve?

Spamfilter: enter image description here

Community
  • 1
  • 1
Nicolas
  • 2,277
  • 5
  • 36
  • 82
  • Not all companies and mail servers reply with non delivery messages - it is often turned off to avoid fishing – BugFinder Apr 26 '16 at 08:13
  • 1
    You cannot make sure that the email address really exists inside your code. There may be several reasons from bounces to invalid domain for the reason that your email is not delivered. Therefore, you should listen for the delivery status messages if sent by the server. In addition, you should store your own white/black list databases as commercial providers such as sendgrid, mailchimp etc. do. – ali Apr 26 '16 at 08:20

1 Answers1

2

I dont think that you will get an error here because the To Method takes either an string or an MailAdress which will also takes an string as input.

So every Adress will be accepted here. Have you tried to place some not allowd characters like ' " % or something like this? I guess you will get an exception here. Everything else will be forwared to the smtp and the he will take care of the delivery and not your C# Code.

Regards Andre

Andre Fritzsche
  • 126
  • 2
  • 11