Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
I Can’t Send E-Mail from localhost; Cannot connect to SMTP server

I see this question asked over and over in the ASP.NET forums and many times the answer is you have to have an SMTP server on your local machine. The person asking the question is usually under the wrong impression that setting the SMTP server property to localhost is all they need to do and e-mail will magically be sent from their web server.

Back in July I introduced you to Neptune, a local SMTP server for testing. If you are developing this is a great tool to use to test e-mail functionality while you are developing. But this still does not explain what that SMTPServer property is all about. This is where you can either pass the IP address or the fully qualified domain of the SMTP server you can use to send e-mail.

When you configure your e-mail client, think MS Outlook, you have to provide both a POP and SMTP server. You can’t just send e-mail from your own machine, unless you have an SMTP server running on your local machine. The SMTP protocol is defined in a series of RFCs. You can read more about SMTP on Wikipedia if you want.

But here is the reality, you cannot just send e-mail from .NET without having an SMTP server to actually send the message. A server can be anything from a simple tool like Neptune up to a full blown server like Exchange. In between you can install the SMTP server that ships with IIS 6.0 or many other SMTP servers. But you need to be aware of how to secure them to safeguard them from being compromised by Spammers. Even inside your company’s firewalls or at home, your ISP and system admins may only allow you to use an authorized mail server. So do check with them for the address you need to use.

So the next time you get an error, ‘Cannot connect to SMTP server’, ask if you actually have an SMTP server to connect to. If not find the one you can use.

Posted: Sunday, September 06, 2009 11:15 PM

by Chris Love
Filed under: ,

Comments

Guy Harwood said:

May be also worth mentioning the SpecifiedPickUpDirectory setting in web.config that allows you to have outgoing emails dropped in a folder on your PC. http://dotnettipoftheday.org/tips/smtp-delivery-method-SpecifiedPickupDirectory.aspx
# September 7, 2009 3:04 AM

Servefault.com said:

Thank you for submitting this cool story - Trackback from Servefault.com

# September 23, 2009 12:34 AM

r4 nintendo ds said:

quite cool. I did not know that many ISP do not allow to connect all the servers. So if I make a SMTP server at my home and try to connect from my office, it is not necessary that I would be able to connect it. Great!!!!
# September 24, 2009 7:20 AM

anuj said:

can u please post the complete detail of the things to do before sending an email from the local machine. Thamks..
# September 29, 2009 4:01 AM

wilber starks@yahoo.com said:

can u please post the complete detail of the things to do before sending e-mailfrom the local machine Thanks.
# October 23, 2009 8:52 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS