2013-12-16 44 views
0

我有一个程序发送带有附件的电子邮件,它在家中有良好的互联网连接正常工作,但当我使用较慢的连接时超时。电子邮件超时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 [email protected]"; 
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"); 

回答

1

使用SmtpClient

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

timeout属性指定以毫秒为单位的超时值。默认值是100,000(100秒)。

通过调用SmtpServer一个变量,它实际上是一个SmtpClient的方式是非常不好的做法

欲了解更多详情,请参阅 this link

1

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