从localhost发送asp.net中的电子邮件

时间:2012-12-15 12:52:01

标签: asp.net email smtp localhost

我找到this 发送邮件的解决方案,但它让我感到很恐怖。这是我的价值观:

Message to: anton_putov@mail.ru

Message from: anton_putov@mail.ru

subject: ....
.........

我正在使用visual studio 2010.我必须设置任何配置属性或其他东西吗?

1 个答案:

答案 0 :(得分:4)

您使用的是哪种类型的SMTP?如果您没有自己的SMTP设置,则可以使用Google Mail。在这里你可以使用它。

MailMessage mail = new MailMessage();
  mail.To.Add("Email ID where email is to be send");
  mail.To.Add("Another Email ID where you wanna send same email");
  mail.From = new MailAddress("YourGmailID@gmail.com");
  mail.Subject = "Email using Gmail";

  string Body = "Hi, this mail is to test sending mail"+ 
                "using Gmail in ASP.NET";
  mail.Body = Body;

  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient();
  smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
  smtp.Credentials = new System.Net.NetworkCredential
       ("YourUserName@gmail.com","YourGmailPassword");
//Or your Smtp Email ID and Password
  smtp.EnableSsl = true;
  smtp.Send(mail);