4 c# asp.net email asp.net-mvc iis-7
我是.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);
}
Run Code Online (Sandbox Code Playgroud)
现在,当我执行此代码时,我将得到以下异常:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
Run Code Online (Sandbox Code Playgroud)
现在我对IIS管理器和其他东西非常陌生.所以那里可能有些不对劲.
我是否需要安装虚拟SMTP服务器?目前我有以下设置:
http://img153.imageshack.us/img153/695/capture2p.png
我一直在寻找几个小时,但我似乎无法找到一个有效的解决方案.
帮助将不胜感激!
在你打电话的时候
SmtpClient smtp = new SmtpClient("127.0.0.1");
Run Code Online (Sandbox Code Playgroud)
localhost上应该有一个SMTP服务器.如果不存在,则可以使用网络的MailServer.
出于测试目的,您可以使用
<system.net>
<mailSettings>
<smtp from="Test@test.com" deliveryMethod="SpecifiedPickupDirectory">
<network host="127.0.0.1" port="25" userName="userID" password="*****" defaultCredentials="true" />
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
这将在C:\ temp\mail中保存您的电子邮件而不发送它.
| 归档时间: |
|
| 查看次数: |
6835 次 |
| 最近记录: |