2017-06-09 8 views
0

ユーザーがフォームを送信したときに電子メールを送信するWebフォームのプロトタイプ作成作業が行われました。グーグルでは、これまでのコードビハインド(C#ASP.NETを使用していますが、どこにこの部分が入っているのか分かりませんが、AD.netを使うように言われています):ウェブフォームからメールを送信しよう

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Net.Mail; 

public partial class WebPageSeparated : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    protected void Button1_Click(object sender, EventArgs e) 
    { 
     SmtpClient smtpClient = new SmtpClient("mail.udel.edu", 25); 

     smtpClient.Credentials = new  System.Net.NetworkCredential("******@udel.edu", "**********"); 
     smtpClient.UseDefaultCredentials = true; 
     smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; 
     smtpClient.EnableSsl = true; 
     MailMessage mail = new MailMessage(); 

     //Setting From , To and CC 
     mail.From = new MailAddress("******@udel.edu", "The Ether"); 
     mail.To.Add(new MailAddress("******@udel.edu")); 
     mail.Subject = "Form Submitted"; 
     mail.Body = "User ID " + TextBox3.Text + " submitted a form."; 
     //mail.CC.Add(new MailAddress("[email protected]")); 

     smtpClient.Send(mail); 
    } 

    protected void Button2_Click(object sender, EventArgs e) 
    { 

    } 

    protected void TextBox3_TextChanged(object sender, EventArgs e) 
    { 

    } 
} 

私は、次のエラーを取得しています:

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("[email protected]")); 
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 

私はIPアドレスとメールサーバの両方にpingを実行することができます。私はまた、smtpクライアント名として "smtp.udel.edu"を使用し、同じ結果を持つポート587を試してみました。

答えて

1

電子メールを送信している場所のアカウントの資格情報を明示的に渡します。これを置く:

smtpClient.Credentials = new NetworkCredential("[email protected]", "password");

smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

+0

"UseDefaultCredentials = true"は、資格情報の割り当てを無効にします。 UseDefaultCredentialsプロパティをfalseに設定すると、サーバーに接続するときにCredentialsプロパティで設定された値が資格情報として使用されます。このプロパティを設定する代わりにUseDefaultCredentialsをtrueに設定することができます。 " - ソースhttps://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials(v=vs.110).aspx – JanErikGunnar

+0

@JanErikGunnar私はあなたのコメントごとに答えを更新しました。 –

+0

私はこの行をコメントアウトしました: "//smtpClient.UseDefaultCredentials = true;"同じエラーが発生しました。私は明示的にユーザー名とパスワードを設定しています - 私はちょうど*****を使用しています。私はあなたのユーザー名とパスワードをStackoverflowに掲載したくないからです。 –

0

それは結局のところ、問題は、SMTPサーバ上の2ファクタ認証ました。 2FAなしでダミーのGmailアカウントを作成することで問題は解決します。

関連する問題