我想使用下面的代碼從asp.net(C#)發送電子郵件。ASP.Net無法發送電子郵件
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
請建議我該怎麼做。我試圖根據論壇中的一些答案關閉防火牆,但沒有運氣。
預先感謝您