繁体   English   中英

电子邮件超时C#

[英]Email Timeout C#

我有一个程序发送带有附件的电子邮件,它在家里工作正常,有良好的互联网连接但是当我使用较慢的连接时超时。

有谁知道我是否可以延长时间,以便通过较慢的网络发送。

我使用的代码是

Cursor.Current = Cursors.WaitCursor;

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress(FilePaths.Default.SquadronEmailAddress);
mail.To.Add(FilePaths.Default.Email);
mail.Subject = FilePaths.Default.SquadronNumber + " Gliding Training Return";
mail.Body = "Please find attached todays Training Return from " + FilePaths.Default.SquadronNumber +
    ". Please do not reply to this email address as its unmonitored. " +
    "If you have any questions or require further information please contact the Adj on adj.644vgs@aircadets.org";
mail.Attachments.Add(new Attachment(FilePaths.Default.GlidingTrainingReturnFolder + ("\\Gliding Training Return" + date.ToString("dd-MMM-yyyy") + ".pdf")));

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(FilePaths.Default.SquadronEmailAddress, FilePaths.Default.DatabasePassword);
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show("Email Sent");

您可以通过修改SmtpClient.Timeout属性来更改超时。 它默认为100秒,这已经很多了,所以如果你真的超过了它,你可能想要寻找不同的解决方案。 例如,您可以在某处上传附件并发送链接 - 收件人也会感谢您。

使用SmtpClient类的timeout属性

SmtpServer.timeout = 200000 ; //change it as needed

指定超时值(以毫秒为单位)。 默认值为100,000(100秒)。

顺便说一句,调用SmtpServer一个实际上是SmtpClient的变量是非常糟糕的做法

有关详细信息,请参阅此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM