如何通过gmail smtp服务器向我的公司域发送邮件

时间:2017-12-20 15:09:51

标签: c# email gmail gsuite

我发现很多问题和解决方案都使用gmail发送邮件,但我无法让代码与我公司的域名一起使用。当我使用自己的Gmail时,它就像一个魅力。

我已激活2FA并为这两个帐户生成了密码。当我使用自己的Gmail帐户邮寄时,它可以工作。但是,当我尝试使用我公司的G Suite帐户邮寄时,它无效。我收到了这个例外:

System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at'

这是我的代码:

var client = new SmtpClient("smtp.gmail.com", 587)
{
      UseDefaultCredentials = false,
      Credentials = new NetworkCredential("********@mydomain.nl", "************"),
      EnableSsl = true
};
client.Send("********@mydomain.nl", "*******@live.nl", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();

我已经检查了所有设置10次。我怎样才能让它发挥作用?

0 个答案:

没有答案
相关问题