【解決方法】この問題の解決方法… メールの送信に失敗しました c#


ローカル ホスティングからメールを送信しようとすると問題なく動作しますが、godaddy plesk ホスティング アカウントからメールを送信しようとすると、「メールの送信に失敗しました」というエラーが表示されます。

“System.Net.Mail.SmtpException: メールの送信に失敗しました。 —> System.Net.WebException: リモート サーバーに接続できません —> System.Net.Sockets.SocketException: 接続先が接続されていないため、接続に失敗しました一定時間後に適切に応答しなかったか、接続されたホストが System.Net.ServicePoint の System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) で 74.125.25.108:25 に応答できなかったため、確立された接続が失敗しました。 ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) — 内部例外スタック トレースの終了 — System.Net.ServicePoint.GetConnection(PooledStream PooledStream,オブジェクト所有者、ブール async、IPAddress& アドレス、Socket& abortSocket、Socket& abortSocket6) (System.Net.PooledStream.Activate) (Object owningObject、Boolean async、GeneralAsyncDelegate asyncCallback) at System.Net.PooledStrea m.Activate (Object owningObject, GeneralAsyncDelegate asyncCallback) で System.Net.ConnectionPool.GetConnection (Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) で System.Net.Mail.SmtpConnection.GetConnection (ServicePoint servicePoint) で System.Net.Mail.SmtpTransport .GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) — 内部例外スタック トレースの終了 — System.Net.Mail で.SmtpClient.Send (MailMessage メッセージ) を WebApplication1._Default.Place_Click (オブジェクトの送信者、EventArgs e) で”

try
            {
                //Create the msg object to be sent
                MailMessage msg = new MailMessage();
                //Add your email address to the recipients
                msg.To.Add(someone@gmail.com);
                //Configure the address we are sending the mail from
                MailAddress address = new MailAddress("username@gmail.com");
                msg.From = address;
                msg.Subject = "gmail";
                msg.Body = "gmail";

                //Configure an SmtpClient to send the mail.            
                SmtpClient client = new SmtpClient();
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = true;
                client.Host = "smtp.gmail.com";
                client.Port = 25;

                //Setup credentials to login to our sender email address ("UserName", "Password")
                NetworkCredential credentials = new NetworkCredential("username@gmail.com", "password");
                client.UseDefaultCredentials = true;
                client.Credentials = credentials;

                //Send the msg
                client.Send(msg);

                //Display some feedback to the user to let them know it was sent
                Label1.Text = "Your message was sent!";
            }
            catch (Exception ex)
            {
                //If the message failed at some point, let the user know
                Label1.Text = ex.ToString();
                //"Your message failed to send, please try again."
            }

解決策 6

今、私は解決策を見つけました。 以下のコードは、smtpサーバーを変更するだけでうまくいきます。

try
           {
               //Create the msg object to be sent
               MailMessage msg = new MailMessage();
               //Add your email address to the recipients
               msg.To.Add(someone@any.com);
               //Configure the address we are sending the mail from
               MailAddress address = new MailAddress("user@mydomain.com");
               msg.From = address;
               msg.Subject = "anything";
               msg.Body = "anything";

               //Configure an SmtpClient to send the mail.
               SmtpClient client = new SmtpClient();
               client.DeliveryMethod = SmtpDeliveryMethod.Network;
               client.EnableSsl = false;
               client.Host = "relay-hosting.secureserver.net";
               client.Port = 25;

               //Setup credentials to login to our sender email address ("UserName", "Password")
               NetworkCredential credentials = new NetworkCredential("user@mydomain.com", "Password");
               client.UseDefaultCredentials = true;
               client.Credentials = credentials;

               //Send the msg
               client.Send(msg);

               //Display some feedback to the user to let them know it was sent
               Label1.Text = "Your message was sent!";
           }
           catch (Exception ex)
           {
               //If the message failed at some point, let the user know
               Label1.Text = ex.ToString();
               //"Your message failed to send, please try again."
           }

解決策 5

これに対する解決策は、gmail の smtp サーバーからメールを送信せず、GoDaddy の smtp サーバー経由で送信することです。

http://vandelayweb.com/sending-asp-net-emails-godaddy-gmail-godaddy-hosted/[^]

その理由についての詳しい説明は、こちらで詳しく説明しています。

http://forums.asp.net/post/5825785.aspx[^]

解決策 1

最初に GoDaddy SMTP 設定を確認する必要があります。 ほとんどの場合、間違った設定を行ったためにエラーが発生します。

また、try..catch ブロックを使用してコードをデバッグし、内部例外を追跡してみてください。

解決策 2

やあ

コーディング前

SMTP サーバーを使用してメールを送信できるかどうかを確認し、ポートを確認します。この場合はポート 587 です。
通常は 25(SMTP) 、465(SMTP with SSL) です。

あなたはtelnetすることができます

telnet <サーブ> <ポート>

telnet を使用して電子メールを送信することもできます。

解決策 4

これは、使用しているポートが原因であり、サーバーがそのポートでの要求に応答していません。 ポートを 25 に変更してから、再試行してください。 私は常に25を使用してきましたが、常に機能していました。

コメント

タイトルとURLをコピーしました