0

こんにちは、Gmail 資格情報を使用してメール テンプレートを呼び出してメールを送信しようとしていますが、メールの送信に失敗したという例外がスローされます

SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu@gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
message = new MailMessage();
message.Subject = "Visitor Arrived";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.Body = "EmailTemplate.html";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu@gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(message);

私を助けてください。

4

3 に答える 3

0
            foreach (GnrDataMailInfo dmi in lstDMI)
            {
                MailMessage mail = new MailMessage();
                mail.From = "youremail";

                SmtpClient smtp = new SmtpClient();
                smtp.Port = 25;   // [1]  port
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
                smtp.UseDefaultCredentials = false; // [3] Changed this
                smtp.Credentials = new NetworkCredential(mail.From.ToString(), "password");  // [4] Added this.
                smtp.EnableSsl = false;
                smtp.Timeout = 20000;
                smtp.Host = "yourhost";

                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.HeadersEncoding = System.Text.Encoding.UTF8;
                mail.Subject = dmi.Subject;
                mail.To.Add(dmi.To);
                mail.IsBodyHtml = true;
                mail.Body = dmi.Body;

                smtp.Send(mail);
            }
于 2016-11-03T07:48:26.450 に答える
0

StreamReaderhtml ファイルから読み取るために使用する必要があります....また、MailMessage.BodyFormatプロパティをMailFormat.Html
Use Thisに設定します。

SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu@gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;

using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your 
{                                                         // HTML file
    message = new MailMessage();
    message.Subject = "Visitor Arrived";
    message.SubjectEncoding = System.Text.Encoding.UTF8;
    message.IsBodyHtml = false;
    message.BodyEncoding = System.Text.Encoding.UTF8;
    message.From = new MailAddress("ambarishkesavarapu@gmail.com");
    message.To.Add(lblCPEmail.Text);
    message.Priority = MailPriority.High;

    message.Body = reader.ReadToEnd();  // Load the content from your file...
    //...
}
SmtpServer.Send(message);

HTML ファイルを本文として電子メールを送信する (C#)から部分的に抜粋した回答

于 2013-04-04T07:46:51.710 に答える
0

代わりにポート 465 を使用してください

ポート 465 は smtps 用です。SSL 暗号化は、SMTP レベルの通信の前に自動的に開始されます。

ポート 587 は msa 用で、標準の SMTP ポートとほぼ同じです。MSA は、認証後 (SMTP AUTH など) に電子メールを受け入れる必要があります。DUL 範囲のネットマスターが SMTP ポート (ポート 25) への発信接続をブロックできる場合、発信スパムを阻止するのに役立ちます。

于 2016-11-03T08:00:27.343 に答える