首页 > Windows开发 > 详细

使用C#发送邮件支持 Implicit SSL

时间:2017-02-28 21:57:50      阅读:1255      评论:0      收藏:0      [点我收藏+]

安装Package:

Install-Package AIM

 

使用下面的代码发送:

class Mail
{
    private static string mailAddress = "{you email address}";
    private static string host = "{your host server}";
    private static string userName = "{your user name}";
    private static string password = "{your password}";
    private static string userTo = "{to address}";
    private static void SendEmail(string subject, string message)
    {
        //Generate Message 
        var mailMessage = new MimeMailMessage();
        mailMessage.From = new MimeMailAddress(mailAddress);
        mailMessage.To.Add(userTo);
        mailMessage.Subject = subject;
        mailMessage.Body = message;

        //Create Smtp Client
        var mailer = new MimeMailer(host, 465);
        mailer.User = userName;
        mailer.Password = password;
        mailer.SslType = SslMode.Ssl;
        mailer.AuthenticationMode = AuthenticationType.Base64;

        //Set a delegate function for call back
        mailer.SendCompleted += compEvent;
        mailer.SendMailAsync(mailMessage);
    }

    //Call back function
    private static void compEvent(object sender, AsyncCompletedEventArgs e)
    {
        if (e.UserState != null)
            Console.Out.WriteLine(e.UserState.ToString());

        Console.Out.WriteLine("is it canceled? " + e.Cancelled);

        if (e.Error != null)
            Console.Out.WriteLine("Error : " + e.Error.Message);
    }
}

  

使用C#发送邮件支持 Implicit SSL

原文:http://www.cnblogs.com/reachteam/p/6481040.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!