• 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     }
  • 相关阅读:
    宏开发:excel中添加拼接行
    windows消息简单应用实例
    C#用到windows 消息列表Message类MSG的id代号
    在C#中winform程序中应用nlog日志工具
    sql语句中生成0-10随机数
    div+css布局使用inline-block
    linux在nginx中服务器集群用到session的注意事项
    linux 安装php时不安装mysql客户端或者服务端
    centos 配置apache注意事项
    Apache服务器不能启动查看启动错误信息
  • 原文地址:https://www.cnblogs.com/angelasp/p/3729241.html
Copyright © 2020-2023  润新知