<i id='G5wGZ'><tr id='G5wGZ'><dt id='G5wGZ'><q id='G5wGZ'><span id='G5wGZ'><b id='G5wGZ'><form id='G5wGZ'><ins id='G5wGZ'></ins><ul id='G5wGZ'></ul><sub id='G5wGZ'></sub></form><legend id='G5wGZ'></legend><bdo id='G5wGZ'><pre id='G5wGZ'><center id='G5wGZ'></center></pre></bdo></b><th id='G5wGZ'></th></span></q></dt></tr></i><div id='G5wGZ'><tfoot id='G5wGZ'></tfoot><dl id='G5wGZ'><fieldset id='G5wGZ'></fieldset></dl></div>
<tfoot id='G5wGZ'></tfoot>

<small id='G5wGZ'></small><noframes id='G5wGZ'>

    <bdo id='G5wGZ'></bdo><ul id='G5wGZ'></ul>

      1. <legend id='G5wGZ'><style id='G5wGZ'><dir id='G5wGZ'><q id='G5wGZ'></q></dir></style></legend>

        如何使 SMTP 在 C# 中进行身份验证

        How can I make SMTP authenticated in C#(如何使 SMTP 在 C# 中进行身份验证)
        <i id='SNDRf'><tr id='SNDRf'><dt id='SNDRf'><q id='SNDRf'><span id='SNDRf'><b id='SNDRf'><form id='SNDRf'><ins id='SNDRf'></ins><ul id='SNDRf'></ul><sub id='SNDRf'></sub></form><legend id='SNDRf'></legend><bdo id='SNDRf'><pre id='SNDRf'><center id='SNDRf'></center></pre></bdo></b><th id='SNDRf'></th></span></q></dt></tr></i><div id='SNDRf'><tfoot id='SNDRf'></tfoot><dl id='SNDRf'><fieldset id='SNDRf'></fieldset></dl></div>
          <tbody id='SNDRf'></tbody>

        • <legend id='SNDRf'><style id='SNDRf'><dir id='SNDRf'><q id='SNDRf'></q></dir></style></legend>

          <small id='SNDRf'></small><noframes id='SNDRf'>

            • <bdo id='SNDRf'></bdo><ul id='SNDRf'></ul>

                <tfoot id='SNDRf'></tfoot>
                  本文介绍了如何使 SMTP 在 C# 中进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了使用 SMTP 发送消息的新 ASP.NET Web 应用程序.问题是 smtp 未从发送消息的人那里进行身份验证.

                  I create new ASP.NET web application that use SMTP to send message. The problem is the smtp was not authenticated from who send the message.

                  如何使 SMTP 在我的程序中通过身份验证?C# 是否有一个具有输入用户名和密码属性的类?

                  How can I make SMTP authenticated in my program? does C# have a class that have attribute for enter username and password?

                  推荐答案

                  using System.Net;
                  using System.Net.Mail;
                  
                  using(SmtpClient smtpClient = new SmtpClient())
                  {
                      var basicCredential = new NetworkCredential("username", "password"); 
                      using(MailMessage message = new MailMessage())
                      {
                          MailAddress fromAddress = new MailAddress("from@yourdomain.com"); 
                  
                          smtpClient.Host = "mail.mydomain.com";
                          smtpClient.UseDefaultCredentials = false;
                          smtpClient.Credentials = basicCredential;
                  
                          message.From = fromAddress;
                          message.Subject = "your subject";
                          // Set IsBodyHtml to true means you can send HTML email.
                          message.IsBodyHtml = true;
                          message.Body = "<h1>your message body</h1>";
                          message.To.Add("to@anydomain.com"); 
                  
                          try
                          {
                              smtpClient.Send(message);
                          }
                          catch(Exception ex)
                          {
                              //Error, could not send the message
                              Response.Write(ex.Message);
                          }
                      }
                  }
                  

                  你可以使用上面的代码.

                  You may use the above code.

                  这篇关于如何使 SMTP 在 C# 中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                  <i id='YqCPl'><tr id='YqCPl'><dt id='YqCPl'><q id='YqCPl'><span id='YqCPl'><b id='YqCPl'><form id='YqCPl'><ins id='YqCPl'></ins><ul id='YqCPl'></ul><sub id='YqCPl'></sub></form><legend id='YqCPl'></legend><bdo id='YqCPl'><pre id='YqCPl'><center id='YqCPl'></center></pre></bdo></b><th id='YqCPl'></th></span></q></dt></tr></i><div id='YqCPl'><tfoot id='YqCPl'></tfoot><dl id='YqCPl'><fieldset id='YqCPl'></fieldset></dl></div>

                      <tfoot id='YqCPl'></tfoot>
                      • <bdo id='YqCPl'></bdo><ul id='YqCPl'></ul>

                        <small id='YqCPl'></small><noframes id='YqCPl'>

                        <legend id='YqCPl'><style id='YqCPl'><dir id='YqCPl'><q id='YqCPl'></q></dir></style></legend>
                          <tbody id='YqCPl'></tbody>