2013-12-16 46 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秒,這已經很多了,所以如果你真的超過了這個,你可能會想要尋找一個不同的解決方案。例如,您可以上傳附件,然後發送鏈接 - 收件人也會感謝您。