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

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

      3. <legend id='E9qO6'><style id='E9qO6'><dir id='E9qO6'><q id='E9qO6'></q></dir></style></legend>

      4. smtp 异常发送邮件失败?

        smtp exception Failure sending mail?(smtp 异常发送邮件失败?)
          <bdo id='Ca3oc'></bdo><ul id='Ca3oc'></ul>

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

            • <legend id='Ca3oc'><style id='Ca3oc'><dir id='Ca3oc'><q id='Ca3oc'></q></dir></style></legend>
                    <tbody id='Ca3oc'></tbody>

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

                  本文介绍了smtp 异常发送邮件失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  StringBuilder emailMessage = new StringBuilder();
                  emailMessage.Append("Dear Payment Team ,");
                  emailMessage.Append("<br><br>Please find the Payment instruction");    
                  
                  try
                  {
                      MailMessage Msg = new MailMessage();
                      // Sender e-mail address.
                      Msg.From = new MailAddress("pqr@gmail.com");
                      // Recipient e-mail address.
                      Msg.To.Add("abc@gmail.com");
                      Msg.CC.Add("zcd@gmail.com");
                      Msg.Subject = "Timesheet Payment Instruction updated";
                      Msg.IsBodyHtml = true;
                      Msg.Body = emailMessage.ToString();
                      SmtpClient smtp = new SmtpClient();
                      //smtp.EnableSsl = true;
                  
                      smtp.Host = ConfigurationManager.AppSettings["HostName"];
                      smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
                      smtp.Send(Msg);
                      Msg = null;
                      Page.RegisterStartupScript("UserMsg", "<script>alert('Mail has been sent successfully.')</script>");
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("{0} Exception caught.", ex);
                  }
                  

                  在 web.config 中添加了这段代码

                  <appSettings>
                      <add key="HostName"   value="The host name as given by my company" />
                      <add key="PortNumber" value="25" />
                  </appSettings>
                  

                  我不断收到异常尝试更改指定的端口号但没有成功

                  I keep getting an exception tried changing the port number as specified but no success

                    System.Net.Mail.SmtpException was caught
                    Message=Failure sending mail.
                    Source=System
                    StackTrace:
                         at System.Net.Mail.SmtpClient.Send(MailMessage message)
                         at PAYMENT_DTALinesfollowup.Sendbtn_Click(Object sender, EventArgs e) in d:AFSS-TFSAFSSCodeERPNETPAYMENTDTALinesfollowup.aspx.cs:line 488
                    InnerException: System.Net.WebException
                         Message=Unable to connect to the remote server
                         Source=System
                         StackTrace:
                              at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
                              at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
                              at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
                              at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
                              at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
                              at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
                              at System.Net.Mail.SmtpClient.GetConnection()
                              at System.Net.Mail.SmtpClient.Send(MailMessage message)
                         InnerException: System.Net.Sockets.SocketException
                              Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 125.63.68.148:25
                              Source=System
                              ErrorCode=10060
                              NativeErrorCode=10060
                              StackTrace:
                                   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                                   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
                              InnerException: 
                  

                  推荐答案

                  您需要提供 smtp 的用户名和密码.

                  You need to give Username and password for smtp.

                  使用下面的代码:-

                      MailSettings.SMTPServer = Convert.ToString(ConfigurationManager.AppSettings["HostName"]);
                      MailMessage Msg = new MailMessage();
                      // Sender e-mail address.
                      Msg.From = new MailAddress("pqr@gmail.com");
                      // Recipient e-mail address.
                      Msg.To.Add("abc@gmail.com");
                      Msg.CC.Add("zcd@gmail.com");
                      Msg.Subject = "Timesheet Payment Instruction updated";
                      Msg.IsBodyHtml = true;
                      Msg.Body = emailMessage.ToString();
                      NetworkCredential loginInfo = new NetworkCredential(Convert.ToString(ConfigurationManager.AppSettings["UserName"]), Convert.ToString(ConfigurationManager.AppSettings["Password"])); // password for connection smtp if u dont have have then pass blank
                  
                      SmtpClient smtp = new SmtpClient();
                      smtp.UseDefaultCredentials = true;
                      smtp.Credentials = loginInfo;
                      //smtp.EnableSsl = true;
                      //No need for port
                      //smtp.Host = ConfigurationManager.AppSettings["HostName"];
                      //smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
                       smtp.Send(Msg);
                  

                  这篇关于smtp 异常发送邮件失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 列表框上的取消选择)
                  <tfoot id='QUg6T'></tfoot>

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

                      <tbody id='QUg6T'></tbody>

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

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

                          • <small id='QUg6T'></small><noframes id='QUg6T'>