直接上代码:
/// <summary> /// /// </summary> /// <param name="from">发送者</param> /// <param name="to">接受者</param> /// <param name="subject">标题</param> /// <param name="body">正文</param> /// <param name="host">服务器</param> /// <param name="username">用户名</param> /// <param name="password">密码</param> /// <returns>发送成功的条数</returns> public static int sendMail(string from, string to, string subject, string body, string host, string username, string password) { try { int n = 0; MailAddress fromAdd = new MailAddress(from); MailMessage mail = new MailMessage(); mail.Subject = subject; mail.From = new MailAddress(from); mail.Body = body; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Host = host; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(username, password); client.DeliveryMethod = SmtpDeliveryMethod.Network; string[] toAdd = to.Split(';'); foreach (string temp in toAdd) { mail.To.Add(new MailAddress(temp)); client.Send(mail); mail.To.Clear(); n++; //WriteInfo("发送成功:"+temp); } return n; } catch (Exception ex) { throw ex; } }
微信扫码查看本文
发表评论