1

This is how I am sending email:

        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);

Is there any setting that I need to enable in G Suite Admin? I need to send email from support@big-apps.org

enter image description here

Faizan Mubasher
  • 4,427
  • 11
  • 45
  • 81
  • 1
    First thing to check: [Turn On Access for less secure apps](https://stackoverflow.com/a/32457468/205233). – Filburt Jun 24 '19 at 17:57
  • 2
    I think the gmail port 587 usually works for me. I haven't tried 465 to be sure if that works. – Wiz Jun 24 '19 at 19:38
  • Possible duplicate of [What is the difference between ports 465 and 587?](https://stackoverflow.com/questions/15796530/what-is-the-difference-between-ports-465-and-587) – paulsm4 Jun 24 '19 at 19:50
  • @Wiz Facing this exception now: `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` – Faizan Mubasher Jun 29 '19 at 03:54

1 Answers1

2

The port 465 is the issue. The SmtpClient EnableSsl option is actually using TLS. Gmail's TLS port is 587.

From Microsoft's Documentation:

https://learn.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.

Community
  • 1
  • 1
Wiz
  • 406
  • 3
  • 7
  • Facing this exception now: `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` – Faizan Mubasher Jun 29 '19 at 03:54
  • Double check the username/password. You also may need to enable "Less Secure Apps" in the Gmail security settings for the account. Gmail considers SMTP to be a less secure method of authentication. If you use Two Factor authentication, you may need to create an "app password" instead. – Wiz Jul 01 '19 at 13:56