ASP.NET: How To Send Email When Your SMPT Server Requires Authentication
I ran into this problem that I simply could not for the life of me figure out. My main site, www.columbussupply.com, has never had any problems sending email via my usual SMTP server. However, I have a couple sites using the same host in my account at Successful Hosting (a FANTASTIC webhost, by the way, if for no other reason than the spectacular customer service [no they did not pay me a dime to say this]), and I was having problems with my new site, www.proudwearsports.com, sending email. The error I kept receiving was:
System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: sorry, that domain isn’t allowed to be relayed thru this MTA (#5.7.1)
After talking with Wade (at Successful Hosting) about my issue, he quickly diagnosed the problem. Apparently, their server requires authentication (ie, logging in) before sending any mail. The server was simply not allowing me to send mail from the site without the proper authentication. So, we went through my code, and there just wasn’t anywhere in the System.Net.Mail class that would allow me to authenticate the email before I sent it, which had me confused (if there is, in fact, a way to do this programmatically, please correct me!). But, after a bit of searching I came up with the following magical Web.config code:
<network host=”whatever.yoursmtphostis.com” password=”yourpassword” userName=”firstname.lastname@example.org” />
And that’s it! Once I put that in, the email was sent and everyone went on with their day with a big ol’ smile on their face.