The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Using localhost as mailserver (5.7.1 Unable to relay for xxx)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Peter van Ooijen

Posts: 284
Nickname: petergekko
Registered: Sep, 2003

Peter van Ooijen is a .NET devloper/architect for Gekko Software
Using localhost as mailserver (5.7.1 Unable to relay for xxx) Posted: Apr 5, 2006 4:43 AM
Reply to this message Reply

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.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Peter van Ooijen
Latest Posts From Peter's Gekko

Advertisement

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.

private static void SendMailWithIIS(string subject, string body, string to)

{

    MailMessage message = new MailMessage();

    message.From =  new MailAddress("Me@Spammer.net");

    message.To.Add(to);

    message.Subject = subject;

    message.Body = body;

    message.BodyEncoding = System.Text.Encoding.ASCII;

    message.IsBodyHtml = true;

    message.Priority = MailPriority.Normal;

 

    SmtpClient smtp = new SmtpClient("Localhost");

    smtp.Send(message);

}

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 !

Share this post: Email it! | bookmark it! | digg it! | reddit!

Read: Using localhost as mailserver (5.7.1 Unable to relay for xxx)

Topic: Refactoring Databases Previous Topic   Next Topic Topic: Jan/Feb/March Books

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use