简体   繁体   中英

Sending mail using C# (Does it needs specific IIS configuration)?

I have just installed IIS, and I want to enable sending emails through C#.I don't know what I need to configure in IIS.
I tried few things but invain. I'm very beginner in ASP.net.

The code I use is the following one.

// create mail message object
MailMessage mail = new MailMessage();
mail.From = @"asaf.tobi@gmail.com";// put the from address here
mail.To = @"asaf.tobi@gmail.com"; // put to address here
mail.Subject = "test";  // put subject here 
mail.Body = "test";// put body of email here
SmtpMail.SmtpServer = "localhost"; // put smtp server you will use here 
// and then send the mail

Under IIS7 you need to go to your mail settings inside the IIS Manager.

Take a look at http://technet.microsoft.com/en-us/library/cc772058(WS.10).aspx

In short

  • Go to IIS Manager
  • Go to the top level site to configure for all of the server or go to your specific site
  • Open the Feartures View
  • Open SMTP Email
  • Set the appropriate mail details

If you need to install a mail server, take a gander at http://learn.iis.net/page.aspx/751/configure-smtp-e-mail-in-iis-7/ for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM