当前位置:编程学习 > C#/ASP.NET >>

邮件发送组件

1.先添加引入命名空间 System.Net.Mail

 

2.组件代码:

/// <summary>
/// 邮件发送组件 
/// </summary>
public class EmailUtils
{
    static EmailUtils() {
        MailHost = ConfigurationManager.AppSettings["mailHost"];
        MailUserName = ConfigurationManager.AppSettings["mailUserName"];
        MailPsw = ConfigurationManager.AppSettings["mailPsw"];
        MailFrom = ConfigurationManager.AppSettings["mailFrom"];
    }
    public static string MailFrom {
        get;
        set;
    }
    public static string MailHost {
        get;
        set;
    }
    public static string MailUserName {
        get;
        set;
    }
    public static string MailPsw {
        get;
        set;
    }
    /// <summary>
    /// 发送邮件 
    /// </summary>
    /// <param name="mailto">发送到</param>
    /// <param name="title">标题</param>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static bool Send(string mailto, string title, string msg) {
        var client = new SmtpClient();
        client.Host = MailHost;
        client.UseDefaultCredentials = false;
        client.Credentials = new System
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,