当前位置:首页 > vs2005 邮件发送代码

vs2005 邮件发送代码

点击次数:1195  更新日期:2010-12-30
\n


\n

/**//// <summary>
/// 发送系统邮件
/// </summary>
/// <param name=”email”>收件人</param>
/// <param name=”body”>内容</param>
/// <param name=”subject”>标题</param>
/// <param name=”cc”>抄送人</param>
/// <returns></returns>
public static bool SendM(MailAddressCollection email, string body, string subject, MailAddressCollection cc)
{
//try
//{
if (email != null && email.Count > 0)
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
//mm.From = “webservice@*****.***”;

mm.IsBodyHtml = true;
mm.Body = body;


\n

foreach (MailAddress m in email)
mm.To.Add(m);
if (cc != null && cc.Count > 0)
{
foreach (MailAddress s in cc)
mm.CC.Add(s);
}
mm.Priority = System.Net.Mail.MailPriority.High;


\n

mm.Subject = subject;
System.Net.Mail.SmtpClient sc = new SmtpClient();
//sc.Host = “mail.pypo.net”;
sc.Send(mm);
return true;
}
else
return false;
//}
//catch
//{
// return false;
//}
}
在webconfig设置


\n


<system.net>
<mailSettings>
<smtp from=”****@*****.***” >
<network host=”mailhost” port=”25″ userName=”webservice” password=”*******”/>
</smtp>
</mailSettings>
</system.net>另,要注意SMTP的设置,SMTP属性->访问->中继权限,最好选择“仅以下列表除外”(也可以选择“仅以下列表” 自己添加允许的列表)

来源:http://blog.csdn.net/eduxh

\n