0
我試圖從我的C#web應用程序中打gmail smtp服務器,但得到以下錯誤:
1)失敗發送消息
2)「操作已超時。
使用C#打開Gmail的smtp服務器,但獲得很少的錯誤。請建議
以下是我的代碼,
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(to);
message.Subject = Name;
message.IsBodyHtml = true;
message.Body = "Some Message";
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 465; //587 for TLS 465 or 25 SSL
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(from, fromPassword);
smtpClient.Timeout = 50000;
smtpClient.Send(message);
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
Console.WriteLine("InnerException is: {0}", ex.InnerException);
}
}
請建議我已經使用端口587,以及嘗試過,但都顯示了同樣的錯誤。下面
後的相關部分,而一個鏈接,以避免downvotes – tharif