次のコードを使用してサーバーからgmailaccountでメールを送信しようとしています。c#接続されたホストが応答に失敗したためにgmail接続に失敗しました
var fromAddress = new MailAddress("[email protected]", "xxxxxx");
var toAddress = new MailAddress(toMailAddress);
const string fromPassword = "xxxxx";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
IsBodyHtml = true,
Subject = mailSubject,
Body = htmlBody
})
{
smtp.Send(message);
}
ファイアウォールにポート587用のInoboundルールがありますが、これはWindowsサーバーに展開すると次の結果になります。私はそれが
この質問をご覧になり、デバッガを使用してコードをステップ実行する方法を学んでください - [C#を使用してGmailアカウントにメールを送信](https://stackoverflow.com/questions/29251189/sending-mail-using -gmail-smtp-csharp-netから) – MethodMan
[C#を使用したGmail SMTPサーバー経由の電子メールの送信]の可能な複製(https://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server- with-c-sharp) –
以下、不思議に受け入れられている答えに対するOP自身のコメントですが、これは、ローカライズされすぎていると判断しました。これは、OPのホスティング会社がファイアウォールのポートを開くことで解決されたためです。 –