<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# 中进行身份验证

        时间:2023-10-06
        <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# 中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 C# 发送带有附件的电子邮件,附件在 Thunderbird 中作为第 1.2 部分到达 下一篇:5.7.57 SMTP - 在 MAIL FROM 错误期间,客户端未通过身份验证发送匿名邮件

                  相关文章

                  <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>