Tried not setting it at all and it didn't work on my server or on a testing
server i have hosted with hsugs.ch.

Been playing around with it today and this is a quick summary of what I've
come across in order to get email working:

1) You need to have .net runtime installed correctly
2) IIS needs to have the Virtual SMTP Server installed
3) Check properties on the virtual smtp server and make sure it has your
machine's name (if you use localhost) or ip address in the "allow to relay"
list.
4) Within your code specify the SmtpServer:

string smtpAddress = ConfigurationSettings.AppSettings["SmtpServerAddress"];
SmtpMail.SmtpServer = smtpAddress;

//Then This

SmtpMail.Send
("[EMAIL PROTECTED]","[EMAIL PROTECTED]","Subject","Email Body");

//Or This

MailMessage mail = new MailMessage();
mail.From = "[EMAIL PROTECTED]";
mail.To = "[EMAIL PROTECTED]";
mail.Subject = "Subject";
mail.Body = "<html><body>Email Body</body></html>";
// Doesn't have to be html format, your choice.
mail.BodyFormat = MailFormat.Html;
SmtpMail.Send(mail);

// Best to use try/catch to log whether or not the email gets sent and to
send a message to the user notifying them that their message hasn't gotten
through.

I used the Config Setting in the web.config file as Dave suggested and it
works great.

On my PC localhost didn't work until I added my computer's name to the
Virtual SMTP Server's allow relay list.

Got it working now and easily configurable in case I change hosts etc.

Thanks for the feedback and help.

John

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to