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 = "Angel_asp@126.com";
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     }
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值