Monday 3 September 2007

E-mailing from ASP.NET

I've been working on a website for a while now. As a base, I use the book ASP.NET 2.0 Website Programming: Problem - Design - Solution (Programmer to Programmer). Now using that, you actually add code to have E-mail sent from within your application using SMTP.

However, I couldn't get it to work. My E-mail address seemed valid enough, as did the code in my web.config:




Since I was planning on adding a new feature to the existing code to E-mail a new member a link they have to click before having their account activated, it seemed like a good idea to first sort out the whole mail thing.

I fiddled with a few things, but kept getting a: "5.7.1 Unable to relay for " error.


The solution is laughably simple (thankfully). Go to Internet Information Services (under Administrative Tools), expand your IIS server, and select right-click the Default virtual SMTP server. Select Properties, and go to the Access tab.

Under the "Relay restrictions" section, click the "relay" button. There, ensure the "Only the list below" option is selected, and press the "Add" button.

Under "Single computer", fill in 127.0.0.1, and click OK. That's it!

For security's sake, I chose to uncheck the checkbox named "Allow all computers which succesfully authenticate to relay".

No comments: