asp.net C#发送邮件类
很久前写的一个简单邮件发送类分享给大家:
1 using System; 2 using System.Data; 3 using System.Configuration; 4 using System.Web; 5 using System.Web.Security; 6 using System.Web.UI; 7 using System.Web.UI.WebControls; 8 using System.Web.UI.WebControls.WebParts; 9 using System.Web.UI.HtmlControls; 10 using System.Net.Mail; 11 12 /// <summary> 13 /// 发送 E-mail 帮助类 14 /// </summary> 15 public class EmailHelper 16 { 17 //发送邮件的帐号 18 private string from = ""; 19 //接收邮件的帐号 20 private string to = ""; 21 //smtp服务器地址 22 private string smtp = ""; 23 //发送邮件帐号的密码 24 private string fromPWD = ""; 25 private string subject = ""; 26 private string body = ""; 27 28 public EmailHelper(string sTo, string sSubject, string sBody) 29 { 30 //this.from = "[email protected]"; 31 //this.fromPWD = "Angelasp.com"; 32 //this.smtp = "mail.126.com"; 33 34 this.to = sTo; 35 this.subject = sSubject; 36 this.body = sBody; 37 } 38 public EmailHelper(string sFrom, string sTo, string sSmtp, string sFromPWD, string sSubject, string sBody) 39 { 40 // 41 // TODO: 在此处添加构造函数逻辑 42 // 43 this.from = sFrom; 44 this.to = sTo; 45 this.smtp = sSmtp; 46 this.fromPWD = sFromPWD; 47 this.subject = sSubject; 48 this.body = sBody; 49 } 50 /// <summary> 51 /// 发送邮件 52 /// </summary> 53 public void SendMail() 54 { 55 MailAddress mailTOAddr = new MailAddress(this.to); 56 MailAddress mailFromAddr = new MailAddress(this.from); 57 MailMessage mail = new MailMessage(mailFromAddr, mailTOAddr); 58 mail.Subject = this.subject; 59 mail.IsBodyHtml = true; 60 61 //mail. 62 mail.Body = this.body; 63 SmtpClient smtpMail = new SmtpClient(this.smtp); 64 smtpMail.Credentials = new System.Net.NetworkCredential(this.from, this.fromPWD); 65 //smtpMail.EnableSsl = true; //不支持SSL 66 smtpMail.Send(mail); 67 } 68 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。