Automatically check bounced emails via POP3?

大城市里の小女人 提交于 2019-11-30 06:55:48

I have done a great deal of work handling bounce emails and there different types. If you want to be absolutely sure that the email your looking at is indeed a bounce of a specific kind I highly recommend getting a good filter. I have worked with Boogie Tools and it has worked very well. It lets you know what kind of bounce it is, Hard, Soft, Transient or if its even someone trying to unsubscribe. It has a muliple API's including .Net and I found it quite easy to get working.

It's pretty easy to do with a TcpClient. Open the server:

TcpClient tcpClient = new TcpClient();
tcpClient.Connect(POP3Server, POP3Port);
NetworkStream stream = tcpClient.GetStream();

Read the welcome message:

int read = stream.Read(inBuffer, 0, inBuffer.Length);
string response = Encoding.ASCII.GetString(inBuffer, 0, read);
if (response.IndexOf("+OK") != 0) throw new ...;

Write back to the server:

byte[] outBuffer = Encoding.ASCII.GetBytes("USER " + account + "\r\n");
stream.Write(outBuffer, 0, outBuffer.Length);

That sends the USER command. You need to login and then you can start grabbing messages - see the POP3 RFC for the full list of commands. If you're not looking to roll your own check out this CodeProject article.

jj33

as abfo says, the POP3 protocol is super simple, getting the messages is a no brainer. Parsing the messages to get the failures is harder, and reliably parsing out which email caused the failure and why it failed is really hard. The problem is that bounce messages don't have a standard format, the default forms vary from MTA to MTA. Then the failure reason can be tweaked by the site admin making it harder to recognize, and the site admin could modify the failure message template which makes it darn near impossible.

See if you can find a .NET mailing list manager and if you can repurpose the bounce handling code. Failing that, see if you can change the tool that's sending the messages to send each email from a unique (and reversible) enveloper sender (VERP I think it's called?). That way you don't need to scan the body of the email, you can tell which recipient failed by examining the recipient address of the failure message.

Thanks for the answer, great! I did some research myself and found ListNanny - also super simple to use and tells you the type of bounce. Will write some proof of concept and see which one I like better...

Your question made me realize that the Wordpress Newsletter plugin I was going to use, did not have bounce management, and I'd need something as well.

I looked around for awhile, and I've settled on the free and open-source PHPlist newsletter manager.

They describe in detail their settings for handling bounces and they do have an experimental advanced bounce handling feature that will allow you to customize the bounce handling exactly the way you want.

Evem if you decide not to use PHPlist, reading how they do it will be useful information for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!