简体   繁体   English

如何使用TLS和System.Net.Mail.SMTPCLient连接到googlemail.com?

[英]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.

相关问题 如何在Xamarin中使用System.Net.Mail.SmtpClient发送邮件 - How to send a mail in Xamarin using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient发送的电子邮件的字体大小 - Font size for an email sent using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient将电子邮件发送到通讯组列表 - Sending email to a distribution list using System.Net.Mail.SmtpClient System.Net.Mail.SmtpClient 在 4.7 中过时了吗? - Is System.Net.Mail.SmtpClient obsolete in 4.7? 如何为电子邮件(System.Net.Mail.SmtpClient)附件设置一个好名称 - How to set a nice name for an e-mail (System.Net.Mail.SmtpClient) attachment 第三方与System.Net.Mail.SmtpClient - Third-party vs System.Net.Mail.SmtpClient 使用TLS和SmtpAuth在.Net 4 / C#中发送带有System.Net.Mail.SmtpClient的电子邮件,可在本地使用,但不能在生产服务器上运行(win 2008 r2) - Sending email with System.Net.Mail.SmtpClient in .Net 4/C# with TLS and SmtpAuth, works locally but not on production server(win 2008 r2) 发送到 System.Net.Mail.SmtpClient 等文件夹 - Send to folder like System.Net.Mail.SmtpClient System.Net.Mail.SMTPClient如何执行其本地IP绑定 - How does System.Net.Mail.SMTPClient do its local IP binding 使用System.Net.Mail.SmtpClient,更改SMTP FROM电子邮件地址 - Using System.Net.Mail.SmtpClient, change the SMTP FROM email address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM