日期:2014-05-18 浏览次数:20474 次
public class MailInfo { private String _sanderAddress; private String _sanderName; private String _sanderPwd; private List<String> _recieverAddress; private String _mailSubject; private String _mailBody; private Attachment _mailAttachment; /// <summary> /// 附件 /// </summary> public Attachment MailAttachment { get { return _mailAttachment; } set { _mailAttachment = value; } } /// <summary> /// 邮件主体 /// </summary> public String MailBody { get { return _mailBody; } set { _mailBody = value; } } /// <summary> /// 邮件标题 /// </summary> public String MailSubject { get { return _mailSubject; } set { _mailSubject = value; } } /// <summary> /// 接收者地址 /// </summary> public List<String> RecieverAddress { get { return _recieverAddress; } set { _recieverAddress = value; } } /// <summary> /// 发送者密码 /// </summary> public String SanderPwd { get { return _sanderPwd; } set { _sanderPwd = value; } } /// <summary> /// 发送者名称 /// </summary> public String SanderName { get { return _sanderName; } set { _sanderName = value; } } /// <summary> /// 发送者地址 /// </summary> public String SanderAddress { get { return _sanderAddress; } set { _sanderAddress = value; } } }
protected static void sendMail(Object obj) { MailInfo mi = (MailInfo)obj; for (int i = 0; i < mi.RecieverAddress.Count; i++) { MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress(mi.RecieverAddress[i])); msg.From = new MailAddress(mi.SanderAddress); msg.Subject = mi.MailSubject; msg.Body = mi.MailBody; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = false; msg.Priority = MailPriority.High; if (mi.MailAttachment != null) { msg.Attachments.Add(mi.MailAttachment); } SmtpClient client = new SmtpClient(); client.Host = "smtp.sina.com.cn"; client.UseDefaultCredentials = false; NetworkCredential basicAuthenticationInfo = new NetworkCredential(mi.SanderName, mi.SanderPwd); client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.Credentials = basicAuthenticationInfo; try { client.Send(msg); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }