自己写的邮件发送类
测试邮箱:网易,QQ
using System; using System.Collections; using System.Net.Sockets; using System.IO; using System.Text; using System.Net.Mail; namespace HuLangCms { /// <summary> /// 邮件发送类 /// </summary> public class MailSender { private string setUserEmail; private string setUserEmailPass; private string setServerName; private int setServerPort; private string setSendMailName; private string setSubject; private string setHtmlBody; /// <summary> /// 发送人邮箱 /// </summary> public string UserEmail { get { return setUserEmail; } set { setUserEmail = value; } } /// <summary> /// 发送人邮箱密码 /// </summary> public string UserEmailPass { get { return setUserEmailPass; } set { setUserEmailPass = value; } } /// <summary> /// 邮件服务器名 /// </summary> public string ServerName { get { return setServerName; } set { setServerName = value; } } /// <summary> /// 邮件服务器端口 /// </summary> public int ServerPort { get { return setServerPort; } set { setServerPort = value; } } /// <summary> /// 收件人邮箱 /// </summary> public string SendMailName { get { return setSendMailName; } set { setSendMailName = value; } } /// <summary> /// 发送邮件主题 /// </summary> public string Subject { get { return setSubject; } set { setSubject = value; } } /// <summary> /// 发送邮件内容 /// </summary> public string HtmlBody { get { return setHtmlBody; } set { setHtmlBody = value; } } /// <summary> /// 执行发送邮件 /// </summary> public void SendMail() { string guidStr = Guid.NewGuid().ToString(); try { MailMessage mm = new MailMessage(setUserEmail, setSendMailName); mm.Subject = setSubject; mm.Body = setHtmlBody; mm.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.Host = setServerName; client.Port = setServerPort; client.Credentials = new System.Net.NetworkCredential(setUserEmail, setUserEmailPass); client.Send(mm); } catch (Exception ex) { if (ex is SmtpException) { ex.ToString(); } else { } } } } }