【发布时间】:2011-02-14 05:01:40
【问题描述】:
我是 .NET 平台的新手。目前我正在学习 ASP.NET MVC。
我想从我的程序中发送一封电子邮件,我有以下代码:
public void sendVerrificationEmail()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("");
mail.To.Add("");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}
现在当我执行这段代码时,我会得到以下异常:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
现在我对 IIS 管理器和其他东西非常陌生。所以那里可能有问题。
我是否需要安装虚拟 SMTP 服务器或其他东西?目前我有以下设置:
http://img153.imageshack.us/img153/695/capture2p.png
我已经找了几个小时了,但似乎找不到可行的解决方案。
我们将不胜感激!
【问题讨论】:
标签: c# asp.net asp.net-mvc email iis-7