前几天为开发的网站做了个发送邮件的功能,但是部署到服务器上无法发送邮件,提示由于目标机器积极拒绝,无法连接。在网上找到了一个解决办法
如果安装了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