C# 无法从 G Suite 公司帐户发送电子邮件

C# Unable to send email from G Suite Company account

这是我发送电子邮件的方式:

        MailMessage m = new MailMessage();
        m.From = new MailAddress("support@big-apps.org", "Big Apps.");
        m.To.Add(new MailAddress("faizan003@gmail.com"));
        m.Subject = "Test Subject";
        m.Body = String.Format("This is Test email");

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 465;
        smtp.EnableSsl = true;
        smtp.Credentials = new System.Net.NetworkCredential()
        {
            UserName = "support@big-apps.org",
            Password = "mypassword"
        };
        smtp.EnableSsl = true;
        smtp.Send(m);

是否需要在 G Suite 管理员中启用任何设置? 我需要从 support@big-apps.org

发送电子邮件

端口 465 是问题所在。 SmtpClient EnableSsl 选项实际上使用的是 TLS。 Gmail 的 TLS 端口是 587。

来自微软的文档:

https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient.enablessl?view=netframework-4.8

The SmtpClient class only supports the SMTP Service Extension for Secure SMTP over Transport Layer Security as defined in RFC 3207. In this mode, the SMTP session begins on an unencrypted channel, then a STARTTLS command is issued by the client to the server to switch to secure communication using SSL. See RFC 3207 published by the Internet Engineering Task Force (IETF) for more information.

An alternate connection method is where an SSL session is established up front before any protocol commands are sent. This connection method is sometimes called SMTP/SSL, SMTP over SSL, or SMTPS and by default uses port 465. This alternate connection method using SSL is not currently supported.