asp.net伺服器上無法發送郵件的問題

來源:互聯網
上載者:User

標籤:

前幾天為開發的網站做了個發送郵件的功能,但是部署到伺服器上無法發送郵件,提示由於目標機器積極拒絕,無法串連。在網上找到了一個解決辦法

如果安裝了McAfee殺毒軟體(按照“手工安裝方法”安裝),首先需對McAfee做以下設定:
開始→程式→Network Associates→VirusScan控制台→右鍵點擊“訪問保護”→屬性→去除“禁止大量發送郵件的蠕蟲發送郵件”前的複選框→確定即可。

記錄一下  另,把發送郵件的方法貼出來:

#region ======發送郵件=====
/// <summary>
/// 發送郵件
/// </summary>
/// <param name="from">寄件者郵箱</param>
/// <param name="fromer">發送人</param>
/// <param name="to">接受者郵箱</param>
/// <param name="toer">收件者</param>
/// <param name="Subject">主題</param>
/// <param name="Body">內容</param>
/// <param name="file">附件</param>
/// <param name="SMTPHost">smtp伺服器</param>
/// <param name="SMTPuser">郵箱</param>
/// <param name="SMTPpass">密碼</param>
/// <returns></returns>
private bool sendemail(string sfrom, string sfromer, string sto, string stoer, string sSubject, string sBody, string sfile, string sSMTPHost, string sSMTPuser, string sSMTPpass)
{
#region ==注釋==
//bool isok = true;
//SmtpClient client = new SmtpClient();
////設定from和to地址
MailAddress from = new MailAddress(sfrom, sfromer);
MailAddress to = new MailAddress(sto, stoer);
////建立一個MailMessage對象
MailMessage oMail = new MailMessage(from, to);
//// 添加附件
if (sfile != "")
{
oMail.Attachments.Add(new Attachment(sfile));
}
////郵件標題
oMail.Subject = sSubject;
////郵件內容
oMail.Body = sBody;
////郵件格式
oMail.IsBodyHtml = true;
////郵件採用的編碼
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
////設定郵件的優先順序為高
oMail.Priority = MailPriority.High;
////發送郵件
SmtpClient client = new SmtpClient();
////client.UseDefaultCredentials = false;
client.Host = sSMTPHost;
client.Port = 25;
client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(oMail);
return true;
}
catch (Exception err)
{
Response.Write(err.Message.ToString());
return false;
}
finally
{
////釋放資源
oMail.Dispose();
}
#endregion

}


#endregion

asp.net伺服器上無法發送郵件的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.