tags:

views:

592

answers:

6
+2  Q: 

POP-Before-SMTP

Recently I had to move one of my web applications to a new hosting provider. The mail and web service is still held on the old hosting site however, when I try to send an email from the new server,I get an error;

"The server rejected one or more recipient addresses. The server response was: 450 : Recipient address rejected: Greylisted for 5 minutes"

I asked my old hosting provider what I need to do to fix this and they replied with

The mail server operates on POP before SMTP. If a valid POP login is not received before sending mail through the server, then the mail is greylisted and held for 5 minutes before a retry.

To prevent this, simply do a Receive before sending mail

Anyone any idea how I do a POP before SMTP in c#?

Thanks for your help.

+2  A: 

i'm not sure how C# would handle the specifics (sockets?), but basically you just want to make a connection to your new POP server. here's a sample POP transaction:

$ telnet new-pop-server.com 110
Connected to new-pop-server.com.
Escape character is '^]'.
+OK
USER <username>
+OK 
PASS <password>
+OK               // you're authenticated at this point 
LIST
+OK 
.                 // no new messages!
QUIT
+OK

once you're authorized you should be able to send your mail programatically. (USER, PASS, LIST, QUIT) are all commands you would send (pop3 RFC).

Owen
+1  A: 

They greylist you because you connect from your new provider, right? Doesn't the new provider have a SMTP which allows connections from the servers IP-range?

Another approach is to do the MX-lookup yourself, and connect directly to the authoritive SMTP-server for which address you're sending email to. However, that also requires you to handle greylisting, meaning, retries on 4xx responses in order to have a reliable delivery.

Maybe you should ask your provider if they provide auth SMTP as an alternative aswell, it's kind of another possible point of failure with the need of POP-login before using the SMTP-service.

jishi
Jishi, yeah the greylist is because I am trying to connect from my new provider to the old provider where my mail and web services are. Not sure if my new provider allows connections from the servers IP-ranger. One thing that I am learning is, using shared hosting is more trouble than it's worth.
Skittles
+1  A: 

I'm pretty sure POP3 is not built into the .NET Framework, so you'll need to implement it yourself as Owen suggested or look for an existing POP3 library such as this one.

Even better would be convincing your new hosting provider to relax that greylisting rule.

C. Dragon 76
+1  A: 

I managed to write the code for this. I am willing to share the solution, (if anyone is interested?) but not sure how best to put the code on Stackoverflow? It's about 50 lines of code.

Skittles
link it on your blog perhaps, if you feel others might want to use it?
Owen
Good idea Owen.. Thanks, I'll do that.. Not sure if other will want to use it but it's better out there than stuck on my D drive..
Skittles
+1  A: 

As suggested I added the code to my blog. It's not the best blog ever published but, someone may find it useful... POP-Before-SMTP

Skittles
+1  A: 

You already have the code you're looking for, but if I may add in my thoughts: Like someone else already suggested, I would check with the old provider whether they provide AUTH with SMTP. To me, what they are saying is that, "You can use SMTP only if you are coming from the same IP range/subnet, or if you have authenticated yourself". A lot of ISPs do this with their SMTP servers. If you are connected through a particular ISP, you can use the SMTP without providing any AUTH credentials explicitly. If you switch to another ISP and want to use the old ISP's SMTP, you'll have to explicitly authenticate with the SMTP server.

ayaz