How to send mails from sql server 2016

  • Hi All

    I am setup mail configuration in sql server database but it is not send and return error. like below is error message.

     

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 9 (2019-04-19T10:43:22). 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). )

     

    Can you Please send some sample code .

     

     

    Regards

    Pols

  • This doesn't sound like you need sample code but that the email server you're connecting to isn't allowing you to send emails. You probably need to talk to the administrator that is responsible for that server.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • This was removed by the editor as SPAM

  • Make sure  the mail server is configured to allow the SQL server to relay messages. Also make sure you have set up the correct credentials for the database mail configuration. This last could be the cause of the "Authentication Required" error.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • i am using my personal mailid like my code is

     

     

    --Creating a Profile

    EXECUTE msdb.dbo.sysmail_add_profile_sp

    @profile_name = 'SQLProfile',

    @description = 'Mail Service for SQL Server';

    -- Create a Mail account for gmail. We have to use our company mail account.

    EXECUTE msdb.dbo.sysmail_add_account_sp

    @account_name = 'SQL_Email_Account',

    @email_address = 'xxxx@gmail.com',

    @mailserver_name = 'smtp.gmail.com',

    @port=587,

    @enable_ssl=1,

    @username='xxxx@gmail.com',

    @password='xxxx'

    -- Adding the account to the profile

    EXECUTE msdb.dbo.sysmail_add_profileaccount_sp

    @profile_name = 'SQLProfile',

    @account_name = 'SQL_Email_Account',

    @sequence_number =1 ;

    -- Granting access to the profile to the DatabaseMailUserRole of MSDB

    EXECUTE msdb.dbo.sysmail_add_principalprofile_sp

    @profile_name = 'SQLProfile',

    @principal_id = 0,

    @is_default = 1 ;

    • This reply was modified 5 years, 8 months ago by  polo.csit.
  • Try enabling the less secure apps setting. Refer to the following which addresses the same error with gmail:

    https://blog.sqlauthority.com/2018/07/04/sql-server-database-mail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated-the-server-response-was-5-5-1-using-gmail/

     

    Sue

  • Allow less secure apps ON but it is not working...error message

     

     

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 9 (2019-04-19T14:14:51). 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). )

  • The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 16 (2019-04-19T14:45:36). Exception Message: Cannot send mails to mail server. (Failure sending mail.). )

  • There are other settings in gmail that can affect this. Other things to try such as Disable two factor authentication,  disable unlock captcha, log into gmail while on the server where you are setting this up. Essentially You need to mess with things on the gmail side.

     

    Sue

  • Still Not Working...

  • It's not a SQL Server issue.  Check the google forums for smtp with gmail - that's what I did when setting up something at home to use gmail.

    Sue

  • Didn't Lowell Aguirre post something on using gmail for this? I think it was several years ago, but should still be applicable.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply