[英]Operation has timed out when sending email using asp.net and smtp.gmail.com
I'm trying to send emails using my asp.net application. 我正在尝试使用asp.net应用程序发送电子邮件。 Here's my code:
这是我的代码:
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);
I've tried 465 and 587 as port numbers, exchanged my credentials because apparently, the older ones in my web.config don't exist anymore, pinged smtp.gmail.com via cmd and it's working properly. 我已经尝试使用465和587作为端口号,交换了我的凭据,因为显然,我的web.config中的旧凭据已不存在,通过cmd ping smtp.gmail.com可以正常工作。 EDIT: it seems that you need to use a gmail account with this method.
编辑:似乎您需要使用带有此方法的gmail帐户。 And yeah, i'm using one.
是的,我正在使用一个。
And the funny thing: the same code, worked yesterday. 和有趣的是:相同的代码,昨天工作。 Is there anything i'm missing here?
我在这里想念什么吗?
EDIT: here's what happened after some testing: 编辑:这是经过一些测试后发生的事情:
1) I've tried to use my private gmail account to see if the same timeout exception would be thrown. 1)我尝试使用我的私人gmail帐户来查看是否会抛出相同的超时异常。 It worked.
有效。 The gmail account i created to be part of the credentials doesn't work.
我创建的作为凭据一部分的gmail帐户不起作用。
2) Now, when i tried to see if the gmail account i created worked, i got this exception: 2)现在,当我尝试查看自己创建的Gmail帐户是否有效时,出现了以下异常:
5.4.5 Daily sending quota exceeded. 5.4.5超出每日发送配额。 n4sm29019478yhc.13 - gsmtp
n4sm29019478yhc.13-gsmtp
So, what? 所以呢? I have a limit of emails i can send per day?
我每天只能发送一封电子邮件吗?
I tried this and it worked 我尝试了这个并且有效
var client = new SmtpClient("smtp.gmail.com", 587)
{
UseDefaultCredentials = false,
EnableSsl = true,
Timeout = 20000,
Credentials = new NetworkCredential("someguy", "password") // gmailid is someguy@gmail.com
};
May be some your config settings are incorrect 可能是您的某些配置设置不正确
So, what?
所以呢? I have a limit of emails i can send per day?
我每天只能发送一封电子邮件吗?
About this, Gmail has a spam protection (and that's usually good). 对此,Gmail具有垃圾邮件防护功能(通常很好)。 After sending some emails, the Gmail requires you to login in Gmail account (site) and the site will ask to you enter a captcha.
发送一些电子邮件后,Gmail要求您登录Gmail帐户(网站),然后该网站会要求您输入验证码。 After the captcha is sent, then you can keep sending emails, but you still have a limit to send emails per day.
验证码发送后,您可以继续发送电子邮件,但是每天发送电子邮件仍然有限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.