"while we're out here, rythm romancin' ..."

Wednesday, November 02, 2005

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.

 

 

1 Comments:

  • Hey,

    I mostly visits this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]drummerboy-sa.blogspot.com really contains lot of useful information. I am sure due to busy scedules we really do not get time to care about our health. Here is a fact for you. Recent Scientific Research indicates that nearly 70% of all USA grownups are either obese or overweight[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these people, you're not alone. Its true that we all can't be like Brad Pitt, Angelina Jolie, Megan Fox, and have sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? You can easily lose with with little effort. You need to improve some of you daily habbits to achive weight loss in short span of time.

    About me: I am author of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health trainer who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.

    By Anonymous Anonymous, at 7:56 PM  

Post a Comment

<< Home