[英]How can I connect to googlemail.com using TLS and System.Net.Mail.SMTPCLient?
I'm testing a normally working emailing module (.Net 4.5.2, C#) based on the System.Net.Mail.SmtpClient class, to which I have added support for TLS. 我正在测试基于System.Net.Mail.SmtpClient类的正常工作的电子邮件模块(.Net 4.5.2,C#),并在其中添加了对TLS的支持。 To do this I'm trying to connect to my personal googlemail.com account using the same smtp settings that I use in my browser.
为此,我尝试使用与浏览器中相同的smtp设置连接到我的个人googlemail.com帐户。 I've set up the SmtpClient object as
我已经将SmtpClient对象设置为
SmtpClient mailer = new SmtpClient();
mailer.Host = "tls://smtp.gmail.com";
mailer.Credentials = new System.Net.NetworkCredential("me@googlemail.com","myGooglemailPassword"); mailer.EnableSsl = true;
mailer.UseDefaultCredentials = true; // although msdn states that this is necessary for TLS, it doesn't actually seeme to make any difference
mailer.Port = 587;
var message = new MailMessage();
message.Subject="dontcare";
message.Body = "dontcare"
message.To.Add("me@googlemail.com");
message.From = new MailAddress("myBusinessEmailaddress@somewhere");
mailer.Send(message);
The problem is that this is rejected by gmail with the error 问题是这被gmail拒绝并显示错误
The SMTP server requires a secure connection or the client was not authenticated.
SMTP服务器需要安全连接或客户端未经过身份验证。 The server response was: 5.5.1 Authentication Required.
服务器响应为:5.5.1需要身份验证。 Learn more at
了解更多信息
Given that my gmail account works normally for me otherwise, what am I missing in the .Net implementation? 鉴于我的gmail帐户对我而言正常工作,.Net实现中缺少什么?
The problem was that by default Googlemail/Gmail blocks email sources that it deems to be 'less secure' (Outlook is an example). 问题是默认情况下,Googlemail / Gmail会阻止它认为“不太安全”的电子邮件源(Outlook是示例)。 You have to turn this off in the Gmail account settings, and then the problem disappears.
您必须在Gmail帐户设置中将其关闭,然后问题消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.