FAQ: Relay Permission for SMTP Mail Server
If your using system.web.mail to send automated mail from within an asp.net application, your’e prob. familiar with the basic approach:
(using System.web.mail)
MailMessage msgNewTask = new MailMessage();
msgNewTask.From = jvanwy@yahoo.com;
msgNewTask.To = jvanwy@yahoo.com;
msgNewTask.Subject = “Read this on your blog!”;
msgNewTask.Body = "<html><head><style type='text/css'><!-- body {font-size : x-small; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;} .GeneralTable {font-size : x-small; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;} .NewsBlurb {background-color : #efefef;padding : 5px;border: 1px solid #c0c0c0;} //--></style></head><body>";
msgNewTask.Body += “some html content here (feel free to use html markup as well);
msgNewTask.Body += "</body></html>";
// msgNewTask.Bcc = strMailBCC;
// msgNewTask.Cc = strMailCc;
msgNewTask.BodyFormat = MailFormat.Html;
SmtpMail.Send(msgNewTask);
However, you might get the error “ Transport failed to connect to the server “ when trying to send the message. This could have a few reasons, (see hrefs at bottom of post). If you get the error when trying to send to email accounts not registered (unknown) to the mail server your using, this helped for me:
Keep in mind that whenever you try to send mail from withing your code, it would pass through the iis virtual smtp server no matter what mail server IP you specify in your code. For this reason you need to configure IIS to allow relaying to email account outside the domain for the mail server IP your using.
So say we’re using the mailserver with IP xxx.xxx.xx.xx to send mail from withing our code, then we need to add xxx.xxx.xx.xx to the Relay list in IIS. How to do that?
Go to IIS – right click on the “virtual smtp server” -> properties -> click the Access tab -> Relay button. This would bring up a list of ip addresses. Click on Add and provide the mail server IP that your using under the ‘Single Computer’ radio button. Click on OK. Make sure the ‘Only the list below’ radio button is selected (you don’t want to allow anyone to use your mail server for spamming or such). It should work without checking the ‘Allow all computers which ‘ option at the bottom of the panel, but if it doesn’t – try checking it on. (it shouldn’t have security issues since only authenticated computers are allowed.)
And that’s it. Try and run your code again after making sure the IP your using in your code is added to the Relay list (above steps).
Here’s my references:
http://www.systemwebmail.com/faq/4.3.9.aspx (check the comments at the bottom)
http://www.upyourasp.net/articles/article.aspx?aid=3
Please feel free to post any comments or feedback. Once again, this is only a basic faq and tutorial on how to send mail using system.web.mail.

0 Comments:
Post a Comment
<< Home