重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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;
        }
    }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


当前标题:C#的Email-创新互联
本文来源:http://cqcxhl.com/article/dhssjs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP