Have you ever configured database mail using Gmail account? There are many articles on the internet describing the steps. In this blog, we would learn about fixing an error “The SMTP server requires a secure connection or the client was not authenticated” which you might see when database mail is used. Note that this can also appear for non-Gmail setups also. So, here we go.
I was working on a project with my client and they had a requirement to send alerts via database mail. They wanted to use Google’s email service i.e. Gmail for this. As soon as they configured and sent a test email, we received below error while sending a test email.
Log Database Mail (Database Mail Log)
Process ID: 2654
Mail Item ID: 23
Last Modified By: sa
Message: The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 4 (DateTime). Exception Message: Cannot send mails to mail server. (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).)
And of course, mail went to unsent/failed state.
It took a while to find a solution as there were many solutions available on the internet. In our case, it was a checkbox. If you run into the same error, make sure that you check below checkbox under account setting section of database mail.
After this, we sent another test email and it was successfully delivered to the recipient.
While searching on the internet, I was also able to find another error which is fixed by the same setting. Here is the error:
Exception Message: Cannot send mails to mail server. (The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first).’
Above error is also due to SSL checkbox.
Reference: Pinal Dave (https://blog.sqlauthority.com)