using System; using System.Collections.Generic; using System.Net.Mail; using System.Text; namespace Insert { public class SendMailHelper { #region 常用邮箱发送邮件服务器 //qq邮箱 public const string QQSmtpServer = "smtp.qq.com"; //网易163邮箱 public const string WYSmtpServer = "smtp.163.com"; //新浪邮箱 public const string XLSmtpServer = "smtp.sina.com.cn"; //谷歌gmail邮箱 public const string GGSmtpServer = "smtp.gmail.com"; #endregion #region 发送邮件 /// <summary> /// Net 2.0 发送邮件 /// </summary> /// <param name="strSmtpServer">发送邮件服务器</param> /// <param name="strFrom">发信人Email</param> /// <param name="strFromPass">发信人Email密码</param> /// <param name="strTo">收信人Email</param> /// <param name="strSubject">邮件主题</param> /// <param name="strBody">邮件内容</param> public static void Send(string strSmtpServer, string strFrom, string strFromPass, string strTo, string strSubject, string strBody) { SmtpClient client = new SmtpClient(strSmtpServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; Byte[] b = Encoding.Default.GetBytes(strBody); strBody = Encoding.GetEncoding("gb2312").GetString(b).ToString(); MailMessage message = new MailMessage(strFrom, strTo, strSubject, strBody); message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; client.Send(message); } #endregion } }
文章评论