最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET Core中使用MialKit實(shí)現(xiàn)郵件發(fā)送功能

 更新時(shí)間:2020年06月16日 22:09:39   作者:愛奔跑的碼農(nóng)  
這篇文章主要介紹了ASP.NET Core中使用MialKit實(shí)現(xiàn)郵件發(fā)送功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

具體代碼如下所示:

# 導(dǎo)包
  首先我們需要導(dǎo)入 MailKit NuGet包,NuGet安裝包命令在下方拓展介紹中。
# 引用命名空間
using MailKit.Net.Smtp;
using MimeKit;
# 郵件發(fā)送幫助類
 /// <summary>
 /// 發(fā)送郵件
 /// </summary>
 /// <param name="Name">發(fā)件人名字</param>
 /// <param name="receive">接收郵箱</param>
 /// <param name="sender">發(fā)送郵箱</param>
 /// <param name="password">郵箱密碼</param>
 /// <param name="host">郵箱主機(jī)</param>
 /// <param name="port">郵箱端口</param>
 /// <param name="subject">郵件主題</param>
 /// <param name="body">郵件內(nèi)容</param>
 /// <returns></returns>
 public async Task<bool> SendMailAsync(string Name, string receive, string sender, string password, string host, int port, string subject, string body)
 {
  try
  {
          # MimeMessage代表一封電子郵件的對象
  var message = new MimeMessage();
          # 添加發(fā)件人地址 Name 發(fā)件人名字 sender 發(fā)件人郵箱
  message.From.Add(new MailboxAddress(Name, sender));
          # 添加收件人地址
  message.To.Add(new MailboxAddress("", receive));
          # 設(shè)置郵件主題信息
  message.Subject = subject;
          # 設(shè)置郵件內(nèi)容
  var bodyBuilder = new BodyBuilder() { HtmlBody = body };
  message.Body = bodyBuilder.ToMessageBody();
  using (var client = new SmtpClient())
  {
   // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
   client.ServerCertificateValidationCallback = (s, c, h, e) => true;
   // Note: since we don't have an OAuth2 token, disable 
   // the XOAUTH2 authentication mechanism. 
   client.AuthenticationMechanisms.Remove("XOAUTH2");
   client.CheckCertificateRevocation = false;
   //client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
   client.Connect(host, port, MailKit.Security.SecureSocketOptions.Auto);
   // Note: only needed if the SMTP server requires authentication
   client.Authenticate(sender, password);
   await client.SendAsync(message);
   client.Disconnect(true);
   return true;
  }
  }
  catch (Exception ex)
  {
  }
  return false;
 }

 借助這一個(gè)簡單的郵件發(fā)送類我們就可以已經(jīng)可以實(shí)現(xiàn)郵件發(fā)送功能了。

# 拓展(NuGet常用命令) 

1、安裝指定版本:install-package <程序包名> -version <版本號>

2、更新包:Update-Package <程序包名>

3、重新安裝所有Nuget包(整個(gè)解決方案都會重新安裝)

  update-package -reinstall

4、重新安裝指定項(xiàng)目所有Nuget包

  update-package -project <項(xiàng)目名稱> -reinstall

5、正常卸載:uninstall-package <程序包名>

6、強(qiáng)制卸載:Uninstall-Package <程序包名> -Force

總結(jié)

以上所述是小編給大家介紹的ASP.NET Core中使用MialKit實(shí)現(xiàn)郵件發(fā)送功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論

灵宝市| 新昌县| 澎湖县| 垣曲县| 靖宇县| 大厂| 邵阳县| 广饶县| 垣曲县| 武川县| 固始县| 洛浦县| 花垣县| 中方县| 景谷| 进贤县| 阳东县| 德钦县| 邯郸县| 十堰市| 泗水县| 宜州市| 东光县| 建阳市| 肇州县| 开江县| 竹北市| 南投县| 乐昌市| 吴江市| 独山县| 黎川县| 佳木斯市| 海林市| 镇沅| 子洲县| 林周县| 扶余县| 梅州市| 泸西县| 修水县|