我正在尝试使用以下代码从asp.net(C#)发送电子邮件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using MovieReviews.Utils;
/// <summary>
/// Summary description for EmailUtil
/// </summary>
public class EmailUtil
{
public static void SendEmail(string to, string name, string from, string body)
{
try
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(from, name);
smtpClient.Host = "localhost";
//Default port will be 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add(to);
message.Subject = "Feedback";
message.IsBodyHtml = false;
// Message body content
message.Body = body;
// Send SMTP mail
smtpClient.Send(message);
}
catch (Exception ex)
{
Logger.LogError(ex);
throw ex;
}
}
}
当我尝试执行时,它会显示:
尝试访问受其访问权限限制的套接字127.0.0.1:25
请建议我该怎么办。我已经按照论坛中的一些答案关闭了防火墙,但没有成功。
提前感谢您的帮助。