.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

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:

<system.net>
  <mailSettings>
   <smtp from=”emailaccountyouaretryingtosendfrom@yourdomain.com”>
    <network host=”whatever.yoursmtphostis.com” password=”yourpassword” userName=”emailaccountyouaretryingtosendfrom@yourdomain.com” />
   </smtp>
  </mailSettings>
 </system.net>

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.

Advertisements

August 16, 2007 - Posted by | ASP.NET, Email, Errors, Tips & Tricks

6 Comments »

  1. thank’s you helped me lot!

    it was the exactly code I neeed!

    Comment by Rotem | July 28, 2008 | Reply

  2. hi,i want to use my super email sender to send emails to my client but any time i send a mail it gose to spam instead of inbox so for me to have this mails delivered to their inbox i have to send emails via SMPT server and i need to put in the user name and password for it to work.please help me thanks.ASAP

    Comment by busho lio | August 12, 2008 | Reply

  3. Busho –

    If you read the post, you’ll see what you have to add at the end of it in your Web.Config file. Another possibility is to talk to your client and have them whitelist your email address so that it won’t go into their SPAM folder.

    Thanks for the comment!

    Comment by Some.Net(Guy) | August 12, 2008 | Reply

  4. You could also consider http://www.asphostcentral.com as it supports sending email right from your web application. they do provide the ASP.NET code for you to send emails.

    Hope this helps you guys…:)

    Comment by Stephen | August 12, 2008 | Reply

  5. Thanks a ton. You saved my day. Hats off!!!

    Comment by Robin | November 7, 2008 | Reply

  6. Thank you so much! You are a lifesaver! 😀

    Comment by Kylie Rasmussen | July 2, 2009 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: