zoukankan      html  css  js  c++  java
  • 使用微软邮箱发送邮件

     System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
     mailMessage.From = new MailAddress("123456@hotmail.com", "**********", Encoding.UTF8);
     mailMessage.To.Add(new MailAddress("*****@126.com"));
    
     mailMessage.Subject = "Test";
     mailMessage.Body = "FYI";
     mailMessage.IsBodyHtml = true;
     mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
     mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
    
     System.Net.Mail.SmtpClient smtp = new SmtpClient();
     smtp.Host = "smtp.live.com";
     smtp.Port = 587;
     smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
     smtp.Timeout = 1000 * 60 * 30;
     smtp.UseDefaultCredentials = false;

       //解决异常: The server response was: 5.7.3 Requested action aborted; user not authenticated
       //chjuqegazuwyznmc 不是邮箱密码,而是微软帐户提供的app password,需要自己配置生成。
       //如果使用邮箱密码,会被认为发送垃圾邮件,而被锁定账号。
       smtp.EnableSsl = true;
       smtp.Credentials = new System.Net.NetworkCredential("123456@hotmail.com", "chjuqegazuwyznmc");

       //解决异常: The remote certificate is invalid according to the validation procedure.

     ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate,
                X509Chain chain, SslPolicyErrors sslPolicyErrors)
                { return true; };
    
     smtp.Send(mailMessage);

    配置生成 app password:

  • 相关阅读:
    .net core 大文件分片上传
    Python 运算符
    CF1398G Running Competition FFT
    Luogu「StOI-2」简单的树 树链剖分+线段树+倍增
    LOJ#3145. 「APIO2019」桥梁 分块+可撤销并查集
    【UNR #4】序列妙妙值 分块+DP
    LuoguP5008 [yLOI2018] 锦鲤抄 tarjan+贪心
    windows提权
    基于 Laravel 框架的内容管理系统
    趣谈、浅析CRLF和LF
  • 原文地址:https://www.cnblogs.com/yipeng-yu/p/5623566.html
Copyright © 2011-2022 走看看