Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试从web表单发送电子邮件_C#_Asp.net_Email_Ado.net_Smtp - Fatal编程技术网

C# 尝试从web表单发送电子邮件

C# 尝试从web表单发送电子邮件,c#,asp.net,email,ado.net,smtp,C#,Asp.net,Email,Ado.net,Smtp,我被赋予了一项任务,让我制作一个web表单的原型,当用户提交表单时,它将发送一封电子邮件。通过谷歌搜索,到目前为止,我已经找到了以下代码(我使用的是C#ASP.NET,有人告诉我使用ado.NET,但我不确定这部分是从哪里来的): 我得到以下错误: Server Error in '/' Application. A connection attempt failed because the connected party did not properly respond after a pe

我被赋予了一项任务,让我制作一个web表单的原型,当用户提交表单时,它将发送一封电子邮件。通过谷歌搜索,到目前为止,我已经找到了以下代码(我使用的是C#ASP.NET,有人告诉我使用ado.NET,但我不确定这部分是从哪里来的):

我得到以下错误:

Server Error in '/' Application.

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 128.175.68.17:25

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: 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 128.175.68.17:25

Source Error: 


Line 31:         //mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
Line 32: 
Line 33:         smtpClient.Send(mail);
Line 34:     }
Line 35: 

Source File: C:\Users\jfalesi\Documents\Jamie_Local\Projects\Data Management\FirstWebSite\WebPageSeparated.aspx.cs    Line: 33 

Stack Trace: 


[SocketException (0x274c): 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 128.175.68.17:25]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +185
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +506

[WebException: Unable to connect to the remote server]
   System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6642460
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +302
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +23
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +328
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +222
   System.Net.Mail.SmtpClient.GetConnection() +45
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1557

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1905
   WebPageSeparated.Button1_Click(Object sender, EventArgs e) in C:\Users\jfalesi\Documents\Jamie_Local\Projects\Data Management\FirstWebSite\WebPageSeparated.aspx.cs:33
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9712662
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

我可以ping IP地址和邮件服务器。我还尝试使用“smtp.udel.edu”作为smtp客户端名称和端口587,结果相同。

明确传递发送电子邮件的帐户的凭据。这样说:

smtpClient.Credentials=新的网络凭据(“user@domain.co.za“,”密码“)


smtpClient.DeliveryMethod=SmtpDeliveryMethod.Network

原来问题是smtp服务器上的双因素标识。创建一个没有2FA的虚拟gmail帐户可以解决这个问题。

“UseDefaultCredentials=true”将使凭据分配无效。要使用默认网络凭据,可以将UseDefaultCredentials设置为true,而不是设置此属性。如果UseDefaultCredentials属性设置为false,则在连接到服务器时,凭据属性中设置的值将用于凭据--source@JanErikGunnar我已根据您的评论更新了答案。我注释掉了这行://smtpClient.usedaultcredentials=true;”并得到了相同的错误。我正在显式设置用户名和密码-我只是使用******,因为我不想在Stackoverflow上发布我的用户名和密码。@Jamesales我看一下:
Server Error in '/' Application.

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 128.175.68.17:25

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: 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 128.175.68.17:25

Source Error: 


Line 31:         //mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
Line 32: 
Line 33:         smtpClient.Send(mail);
Line 34:     }
Line 35: 

Source File: C:\Users\jfalesi\Documents\Jamie_Local\Projects\Data Management\FirstWebSite\WebPageSeparated.aspx.cs    Line: 33 

Stack Trace: 


[SocketException (0x274c): 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 128.175.68.17:25]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +185
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +506

[WebException: Unable to connect to the remote server]
   System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6642460
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +302
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +23
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +328
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +222
   System.Net.Mail.SmtpClient.GetConnection() +45
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1557

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1905
   WebPageSeparated.Button1_Click(Object sender, EventArgs e) in C:\Users\jfalesi\Documents\Jamie_Local\Projects\Data Management\FirstWebSite\WebPageSeparated.aspx.cs:33
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9712662
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639