![](/img/trans.png)
[英]SmtpClient in C# using smtp.Gmail.com:857 with Google's 2 Step Verification activated
[英]Gmail SMTP failure using c# SmtpClient
我們的應用程序可以通過 SmtpClient 發送電子郵件。 我們的一位客戶嘗試使用他的 gmail 帳戶執行此操作,但失敗導致超時。 然而,從我們的測試實驗室它工作得很好(使用另一個 gmail 帳戶)。
在跟蹤中,我可以看到服務器沒有響應證書、服務器密鑰交換、服務器問候完成。 我想知道這可能是什么原因?
我還在跟蹤中注意到,客戶正在使用 TLSv1,所以我嘗試在 Windows7 系統上復制錯誤,但它仍然對我有用。
oSmtp = new SmtpClient(this.host, this.port);
oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
oSmtp.EnableSsl = ssl;
NetworkCredential oCredential = new NetworkCredential(this.userName, this.password);
oSmtp.Credentials = oCredential;
oSmtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
string userState = null;
oSmtp.SendAsync(oMsg, userState);
就代碼而言,enableSsl 是正確的,端口是 587,我們還指示我們的客戶檢查他的 gmail 帳戶並允許不太安全的應用程序。
我們會向客戶詢問更具體的細節,並嘗試在我們的應用程序中添加更多的痕跡,但我想知道是否有任何東西可以阻止服務器使用證書進行應答,...
檢查跟蹤發現客戶 Client Hello 和我們的測試 Client Hello 之間沒有顯着差異。
謝謝!
這是我幾天前使用的工作示例:
string fromAddress = "fromaddress@gmail.com";
var toAddress = new MailAddress("fake@email.com", "To person");
const string fromPassword = "pass";
const string subject = "test";
const string body = "Hey now!!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(fromAddress);
mail.To.Add(toAddress);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
//mail.Attachments.Add(new Attachment("C:\\file.zip"));
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
還要確保為您用於發送數據的 Gmail 啟用不太安全的應用程序訪問:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.