SQL Server – Database Mail Configurations Using Gmail Account

database-mailsql server

After creating a profile and account using gmail account
smtp.gmail.com port 587
I get an error while trying to send a test email

The mail could not be sent to the recipients because of the mail
server failure. Cannot send mail to mail servers(The SMTP server
requires secure connection or the client was not authenticated).

enter image description here

Command for sending

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'Test Profile',  -- my profile name
    @recipients = 'myaddress@gmail.com',  -- my email address, the same one 
                                          -- which is also configured above
    @body = 'This is a test email sent from TEST server',
    @subject = 'TEST EMAIL',
    @importance ='HIGH' 

What I am doing wrong? Or should I change some settings from in my gmail account settings?
Thanks

Best Answer

Basically your error message says what you have to focus on. As SSL is enabled make sure to set ON external unsafe application access in gmail setting and not to forget to refresh your account. If unsafe access is off, gmail will notify you by a message to assure that it is you trying to access and will show the way how to enable if you click yes.