问题描述
我正在尝试使用gmail凭据使用SMTP客户端发送电子邮件。 这是我正在使用的代码
BaseClass<T extends MyType> {
List<T> items;
void addItemFromMap(Map map) {
items.add(T.fromMap(map));
}
}
我收到超时错误
操作已超时
服务不可用,正在关闭传输通道。服务器响应为:并发SMTP连接过多;请稍后再试。
我在做什么错了?
解决方法
最后,我弄清楚了我的代码出了什么问题 更新的代码如下
using (var mail = GetMailInfo())
{
using (SmtpClient client = new SmtpClient("smtp.gmail.com",587)) // port is 587 instead of 465 as mentioned by @jdweng in the comment
{
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false; // this must be before the **Credentials** else this will reset the given credential
client.Credentials = new NetworkCredential("**@gmail.com","Password");
client.EnableSsl = true;
client.Send(mail);
}
}
如果您使用的是gmail,请在顶部转到设置并停用2种方式的身份验证,并激活访问安全性较低的应用
所有这些都可以找到Here