[英]The operation has timed out. while sending email through smtp using C# ASP.net
[英]Operation has timed out when sending email using asp.net and smtp.gmail.com
我正在嘗試使用asp.net應用程序發送電子郵件。 這是我的代碼:
string smtpServer = ConfigurationManager.AppSettings["smtpServer"].ToString();
int smtpPort = int.Parse(ConfigurationManager.AppSettings["smtpPort"]);
string smtpUser;
string smtpPwd;
if (administrativo)
{
smtpUser = ConfigurationManager.AppSettings["smtpUser"].ToString();
smtpPwd = ConfigurationManager.AppSettings["smtpPwd"].ToString();
//smtpUser = "licitacoeslic@gmail.com";
//smtpPwd = "liclicitacoes";
}
else
{
smtpUser = ConfigurationManager.AppSettings["smtpNoReplyUser"].ToString();
smtpPwd = ConfigurationManager.AppSettings["smtpNoReplyPwd"].ToString();
//smtpUser = "licitacoeslic@gmail.com";
//smtpPwd = "liclicitacoes";
}
bool smtpSslEnabled = bool.Parse(ConfigurationManager.AppSettings["smtpSslEnabled"]);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = smtpServer;
if (smtpPort > 0)
smtpClient.Port = smtpPort;
if (smtpUser != String.Empty)
smtpClient.Credentials = new NetworkCredential(smtpUser, smtpPwd);
smtpClient.EnableSsl = smtpSslEnabled;
//transforma a mensagem de e-mail em html para habilitar o uso do logo
MailMessage mm = new MailMessage(de, para, assunto, texto);
mm.IsBodyHtml = true;
smtpClient.Send(mm);
我已經嘗試使用465和587作為端口號,交換了我的憑據,因為顯然,我的web.config中的舊憑據已不存在,通過cmd ping smtp.gmail.com可以正常工作。 編輯:似乎您需要使用帶有此方法的gmail帳戶。 是的,我正在使用一個。
和有趣的是:相同的代碼,昨天工作。 我在這里想念什么嗎?
編輯:這是經過一些測試后發生的事情:
1)我嘗試使用我的私人gmail帳戶來查看是否會拋出相同的超時異常。 有效。 我創建的作為憑據一部分的gmail帳戶不起作用。
2)現在,當我嘗試查看自己創建的Gmail帳戶是否有效時,出現了以下異常:
5.4.5超出每日發送配額。 n4sm29019478yhc.13-gsmtp
所以呢? 我每天只能發送一封電子郵件嗎?
我嘗試了這個並且有效
var client = new SmtpClient("smtp.gmail.com", 587)
{
UseDefaultCredentials = false,
EnableSsl = true,
Timeout = 20000,
Credentials = new NetworkCredential("someguy", "password") // gmailid is someguy@gmail.com
};
可能是您的某些配置設置不正確
所以呢? 我每天只能發送一封電子郵件嗎?
對此,Gmail具有垃圾郵件防護功能(通常很好)。 發送一些電子郵件后,Gmail要求您登錄Gmail帳戶(網站),然后該網站會要求您輸入驗證碼。 驗證碼發送后,您可以繼續發送電子郵件,但是每天發送電子郵件仍然有限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.