我对.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](https://istack.dev59.com/cKr3m.webp)