///<summary>
/// 群發帶附件郵件
///</summary>
///<param name="toAdd">發送地址列表</param>
///<param name="ccAdd">抄送地址列表</param>
///<param name="subject">郵件主題</param>
///<param name="content">郵件內容</param>
///<param name="sendHost">SMTP主機</param>
///<param name="sendUser">SMTP用戶名</param>
///<param name="sendPwd">SMTP密碼</param>
///<param name="sendEmail">發送郵件帳號</param>
///<param name="sendName">發送郵件帳號名</param>
///<param name="attList">附件列表</param>
///<returns></returns>
publicstatic bool SendEmailList(string[] toAdd,string[] ccAdd,string subject,string content,string sendHost,string sendUser,string sendPwd,string sendEmail,string sendName,System.Collections.Generic.List<Attachment> attList) {
try
{
System.Net.Mail.MailMessage message= new System.Net.Mail.MailMessage(); message.From= new MailAddress(sendEmail,string.IsNullOrEmpty(sendName)?"admin":sendName, Encoding.UTF8);//設置發送郵件信息
foreach (string add in toAdd)//接收郵件帳號
{ message.To.Add(add); }
foreach (string addin ccAdd)//抄送郵件帳號
{ message.CC.Add(add); }
message.Subject= subject;//郵件主題
//message.SubjectEncoding=Encoding.UTF8;
//主題編碼
message.Body= content;//郵件內容
//message.BodyEncoding=Encoding.UTF8;
//內容編碼
message.IsBodyHtml= true;
//是否支持HTML
message.Priority= MailPriority.High;//邮件优先级
if (attList!= null&& attList.Count> 0)//添加郵件附件
{
foreach (Attachment attin attList)
{ message.Attachments.Add(att); } }
SmtpClient client= new SmtpClient(sendHost);//设置smtp服务器
client.Credentials= new System.Net.NetworkCredential(sendUser, sendPwd); client.Send(message);return true;
} catch
{return false; } }
code 是网上Copy 的 凑活看吧,