Andrej Kaurin
Andrej Kaurin

Reputation: 11642

Catching bounced email in ASP.NET C#

I am using C# asp.net to send email messages. If email address sending from (message.From) can be any address is there still possibility that application requests report if email was bounced from the server.

Upvotes: 4

Views: 13279

Answers (5)

sbp
sbp

Reputation: 973

Bounced back emails can take seconds, minutes,hours or days depending on the server bouncing back the emails (i.e. the server to which you are sending emails). Also, emails are sent using SMTP client and received on POP and since the bounced back emails need to be received to note the bounce back, there is no way of getting bounce back error when you send email.

You need to add reply-to address to the message you are sending out using smtp client.

message.ReplyToList.Add("<reply-to-address-for-detecting bouncing back emails>");

Then you need to monitor the reply-to address. Now to monitor this using C# you need to create POPClient() associated with reploy-to address using a service or periodic checking arrangement. Here is the StackOverflow link showing how to detect received email.

You could even have IT Support address as the reply to address if applicable to your organization, so that when emails are bounced back you'd be notified (only if non-frequent)

Upvotes: 4

abend
abend

Reputation: 483

If you have access to the smtp's folder structure, you can parse files in the inetpub/mailroot/badmail folder. These files will have the address and the reason for non-delivery in plain text.

Upvotes: 0

rtpHarry
rtpHarry

Reputation: 13125

For a bounce where an email is sent back to the sender saying an error you will need to use the technique outlined by Aristos in this thread.

You can check for errors at the point of sending by catching an SmtpException:

There is no fool proof method to do this though because many email servers will simply discard the email rather than respond. This is to prevent spammers detecting if the email inbox is real account or not.

Upvotes: 0

Joop
Joop

Reputation: 2839

What about the DeliveryNotificationOptions.OnFailure?

Upvotes: 1

Aristos
Aristos

Reputation: 66641

You need here a program that makes time to time pop, and check to see if there is any return from the email you send.

Search on google for asp.net pop3 to find ideas and module that do that think.

I have test my self many of them and for me one of the best is this one http://www.aspnetpop3.com/ that can read and what you say - but is not for free.

last comment, the task you ask to do is a difficult one, and can not be solved just with one function and you defently need database to keep record what you send and what have been bounce back.

Upvotes: 1

Related Questions