SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("*********@gmail.com", "***********");
MailMessage mm = new MailMessage("*********@gmail.com", "******@gmail.com", "delivery.", "tttt");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Attachment fMailAttachment;
fMailAttachment = new Attachment(FilePath);
mm.Attachments.Add(fMailAttachment);
client.Send(mm);
mm.Attachments.Dispose();
我正在尝试使用此代码发送电子邮件。它工作得很好,但只有当我登录我的邮件并让它打开时,当我关闭邮件时它不会发送任何邮件。
该代码有什么问题?
答案 0 :(得分:0)
我编辑后效果很好 client.Timeout = 10000; 至 client.Timeout = 100000;