zoukankan      html  css  js  c++  java
  • 使用C#发送邮件支持 Implicit SSL

    安装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);
        }
    }
    

      

  • 相关阅读:
    JS日期显示格式 yyyy-MM-dd hh:mm:ss
    Html.Partial和Html. RenderPartial
    $.ajax()详解
    B/S 类项目改善
    yaml
    跟我学SpringMVC目录汇总贴、PDF下载、源码下载
    全网最全ASP.NET MVC 教程汇总
    持续集成实践
    http://blog.jobbole.com/50603/#comment-153933
    Java代码优化(转)
  • 原文地址:https://www.cnblogs.com/reachteam/p/6481040.html
Copyright © 2011-2022 走看看