1

このお問い合わせページを localhost から実行すると、正常に動作します。

MailMessage msg=new MailMessage();
//Sender Email
msg.From = new MailAddress(TextBox1.Text);
//Reception Email
msg.To.Add("recieve@gmail.com");
msg.Subject=TextBox2.Text;

String body="Name: "+TextBox4.Text+"\n\nMessage:\n\t"+TextBox3.Text+"";
msg.Body=body;

//SMTP Server
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new NetworkCredential("abc@gmail.com", "password");
smtp.EnableSsl = true;
smtp.Send(msg);

しかし、ウェブサイトをホストするとうまくいきません。このコードの何が問題になっていますか?

このコードは localhost で正常に動作します。

ただし、インターネット上でホストする場合。発生したエラーログです。

System.Net.Mail.SmtpException: SMTP サーバーがセキュリティで保護された接続を必要とするか、クライアントが認証されませんでした。サーバーの応答は次のとおりです。5.5.1 認証が必要です。詳細については、System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net. System.Net.Mail.SmtpClient.Send(MailMessage メッセージ) での Mail.SmtpTransport.SendMail(MailAddress 送信者、MailAddressCollection 受信者、String deliveryNotify、Boolean allowUnicode、SmtpFailedRecipientException& 例外)

4

0 に答える 0