using System; using System.Web; namespace HuaTong.General.Utility { /// <summary> /// 邮件发送 /// </summary> public class EmailHelper { string MailAddress = ""; string MailName = ""; string MailHost = ""; string MailPassword = ""; public EmailHelper(string mailAddress, string mailName, string mailHost, string mailPassword) { MailAddress = mailAddress; MailName = mailName; MailHost = mailHost; MailPassword = mailPassword; } /// <summary> /// 发送邮件 /// </summary> public bool SendMail(string subject, string body, string to, bool Ishtml) { using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage()) { msg.To.Add(to); msg.From = new System.Net.Mail.MailAddress(MailAddress, MailName, System.Text.Encoding.UTF8); msg.Subject = subject;//邮件标题 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 msg.Body = body;//邮件内容 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 msg.IsBodyHtml = Ishtml;//是否是HTML邮件 msg.Priority = System.Net.Mail.MailPriority.Normal;//邮件优先级 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Credentials = new System.Net.NetworkCredential(MailAddress, MailPassword); client.Host = MailHost; object userState = msg; try { client.Send(msg); return true; } catch { return false; } } } } }