zoukankan      html  css  js  c++  java
  • mailkit用163发邮件

    1. 开启SMTP服务,并设置授权码

    2. 代码如下,使用ssl模式连接,用授权码登录

    client.Connect(mtEmailSmtp, 587, true);
    public static void SendEmail(string toEmail, string Title, string bodytxt)
            {
                //以下stmp服务器及用户名密码保证长期有效
                string mtEmailName = "发件人名称";
                string mtEmailSmtp = "smtp.163.com";
                string mtEmailAddress = "发件人@163.com";
                string mtSqm = "授权码";
    
                MimeMessage message = new MimeMessage();
                //发件人
                message.From.Add(new MailboxAddress(mtEmailName, mtEmailAddress));
                //收件人
                message.To.Add(new MailboxAddress( toEmail));
                //标题
                message.Subject = Title;
                //产生一个支持HTml 的TextPart
                TextPart body = new TextPart(TextFormat.Html)
                {
                    Text = bodytxt
                };
    
                //创建Multipart添加附件
                Multipart multipart = new Multipart("mixed");
                multipart.Add(body);
    
                //正文内容,发送
                message.Body = multipart;
                //message.Body = body;
                using (SmtpClient client = new SmtpClient())
                {
                    //Smtp服务器
                    client.Connect(mtEmailSmtp, 587, true);
                    //登录,发送
                    //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了
                    client.Authenticate(mtEmailAddress, mtSqm);
    
                    client.Send(message);
                    //断开
                    client.Disconnect(true);
                }
            }
    

      

  • 相关阅读:
    LeetCode "Jump Game"
    LeetCode "Pow(x,n)"
    LeetCode "Reverse Linked List II"
    LeetCode "Unique Binary Search Trees II"
    LeetCode "Combination Sum II"
    LeetCode "Divide Two Integers"
    LeetCode "First Missing Positive"
    LeetCode "Clone Graph"
    LeetCode "Decode Ways"
    LeetCode "Combinations"
  • 原文地址:https://www.cnblogs.com/wangx036/p/11547151.html
Copyright © 2011-2022 走看看