編集:添付なしでメールを送信できます
メールを送信しようとすると、次のエラーが発生します。
System.Net.Mail.SmtpException: The operation has timed out.
以下は私のコードです:
public static void SendMailMessage(string to, string subject, string body, List<string> attachment)
{
MailMessage mMailMessage = new MailMessage();
// string body; --> Compile time error, body is already defined as an argument
mMailMessage.From = new MailAddress("abc@gmail.com");
mMailMessage.To.Add(new MailAddress(to));
mMailMessage.Subject = subject;
mMailMessage.Body = body;
foreach (string s in attachment)
{
var att = new Attachment(s);
mMailMessage.Attachments.Add(att);
}
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.High;
using (SmtpClient mSmtpClient = new SmtpClient())
{
mSmtpClient.Send(mMailMessage);
}
}
ウェブ設定
<system.net>
<mailSettings>
<smtp from="mailid">
<network host="smtp.gmail.com" port="587" enableSsl="true" userName="username" password="pass" />
</smtp>
</mailSettings>
注 : 添付ファイルの上限を超えていないこと (25 mb 未満)
この問題を解決するにはどうすればよいですか、または何が欠けていますか?