protected void Button1_Click(object sender, EventArgs e)
{
var fromAddress = new MailAddress(fromid.Text, fromname.Text);
var toAddress = new MailAddress(toid.Text, toname.Text);
string fromPassword = pswd.Text;
string subject = subjectbox.Text;
string body = bodybox.Text;
Attachment at = new Attachment(Server.MapPath("~/Penguins.jpg"));
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000,
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = false,
})
{
message.Attachments.Add(at);
smtp.Send(message);
}
}
エラーはありませんが、メールの送信中に時間がかかり、「接続タイムアウト」が表示され、メールが送信されません...:(どこに問題があるのか わかりますか。