This post originated from an RSS feed registered with .NET Buzz
by Peter van Ooijen.
Original Post: Using localhost as mailserver (5.7.1 Unable to relay for xxx)
Feed Title: Peter's Gekko
Feed URL: /error.htm?aspxerrorpath=/blogs/peter.van.ooijen/rss.aspx
Feed Description: My weblog cotains tips tricks and opinions on ASP.NET, tablet PC's and tech in general.
With .NET 2.0 writing code which uses the IIS webserver to send mail has become even more powerful. The System.Net.Mail namespace has some rich classes.
The .NET docs even contain a sample to send mail asynchronous. The hard part lies not in the code but in the configuration of localhost. It considers itself being used as a mail relay and by default it does not allow anyone to do that. In your code you'll get the error message : Mailbox unavailable. The server response was: 5.7.1 Unable to relay for
To fix it you have to configure relay restrictions in the IIS admin.
Here I've set localhost, aka 127.0.0.1, as the only one allowed to relay mail. And now my .NET code can spam everybody. Use with care !