189 8069 5689

C#的Email

这篇Emial用的是用的是第三方的Email引擎,如果你想用自己的邮箱引擎的话,得自己写一个,而且是要收费的.我暂时还没研究邮箱引擎的原理.如果读者知道的话,望赐教.

创新互联公司是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,成都小程序开发,十余年建站对除甲醛等多个方面,拥有丰富建站经验。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// 
///ainyTools 的摘要说明
/// 
public class ainyTools
{
    private  ainyTools(){}
    private static string NO_THIS_USER = "登录失败×您可能还没注册";
    private static string NO_POWERS = "您没有任何权限,请申请";
    private static string NO_THIS_POWER = "您没有此项权限,请申请";
    private static string SURE_COMEIN = "succ";
    private static string SUPER_ID = "superId";
    private static int SESSION_TIME_OUT = 30;
    private static string IS_SUPER = "isSuper";
    private static string IS_ORDINARY = "isOrdinary";
    private static string ERROR_NO_Session = "nS";
    private static string ERROR_NO_Have = "no";
    private static string BACK_FAILE = "f";
    private static string BACK_SUCC = "s";
    private static string Power_App = "权限申请";
    /// 
    /// 权限申请标题
    /// 
    public static string _Power_App
    {
        get { return ainyTools.Power_App; }
    }
    /// 
    /// 操作成功
    /// 
    public static string _BACK_SUCC
    {
        get { return ainyTools.BACK_SUCC; }
    }
    /// 
    /// 操作失败
    /// 
    public static string _BACK_FAILE
    {
        get { return ainyTools.BACK_FAILE; }
    }
    /// 
    /// 没有相关的信息
    /// 
    public static string _ERROR_NO_Have
    {
        get { return ainyTools.ERROR_NO_Have; }
    }
    /// 
    /// 没有Session
    /// 
    public static string _ERROR_NO_Session
    {
        get { return ainyTools.ERROR_NO_Session; }
    }
    //这里是邮件的系统
    private static string mailServerName = "smtp.126.com";  //发送邮件的SMTP服务器
    private static string mailFrom = "XXX@126.com";   //发件人邮箱(用126的邮件服务器,就必须用126邮箱的用户名)
    private static string mailTo = "ROOT@126.com";   //收件人邮箱
    private static string User_Reg_App = "用户注册申请!";
    public static string _User_Reg_App_Title {
        get { return ainyTools.User_Reg_App; }
    }
    public static string _mailServerName {
        get { return ainyTools.mailServerName; }
    }
    public static string _mailFrom {
        get { return ainyTools.mailFrom; }
    }
    public static string _mailTo {
        get { return ainyTools.mailTo; }
    }
    public static string _IS_ORDINARY
    {
        get { return ainyTools.IS_ORDINARY; }
    }
    public static string _IS_SUPER
    {
        get { return ainyTools.IS_SUPER; }
    }
    public static int _SESSION_TIME_OUT
    {
        get { return ainyTools.SESSION_TIME_OUT; }
    }
    public static string _SUPER_ID
    {
        get { return ainyTools.SUPER_ID; }
    }
    public static string _SURE_COMEIN
    {
        get { return ainyTools.SURE_COMEIN; }
    }
    public static string _NO_THIS_POWER
    {
        get { return ainyTools.NO_THIS_POWER; }
    }
    public static string _NO_THIS_USER
    {
        get { return ainyTools.NO_THIS_USER; }
    }
    public static string _NO_POWERS
    {
        get { return ainyTools.NO_POWERS; }
    }
}

邮件发送器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
/// 
///EmailManager 的摘要说明
///收发邮件
/// 
public class EmailManager{
    private EmailManager(){}
    public static bool sendEmailInfo(string title,string body){
        MailAddress from = new MailAddress(ainyTools._mailFrom, "siyecompanyDIZHAI");
        MailMessage mail = new MailMessage();
        mail.Subject = title;
        mail.From = from;
        mail.To.Add(new MailAddress(ainyTools._mailTo, "siyesoft"));
        mail.Body = body;
        mail.BodyEncoding = System.Text.Encoding.UTF8;
        mail.IsBodyHtml = true;
        mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; 
        SmtpClient clientA = new SmtpClient();
        try{
            clientA.Host = ainyTools._mailServerName;
        }catch (Exception e) {
            return false;
        }
        clientA.UseDefaultCredentials = false;
        clientA.Credentials = new System.Net.NetworkCredential("siyecompanyDIZHAI", "填写密码");
        clientA.DeliveryMethod = SmtpDeliveryMethod.Network;
        try{
            clientA.Send(mail);
            return true;
        }
        catch (Exception e1) {
            return false;
        }
    }
}

文章标题:C#的Email
文章源于:http://cdxtjz.cn/article/jesdds.html

其他资讯