Internet——Code之发送邮件

///<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 的 凑活看吧,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值