I have several SQL databases on different servers. I have used a script to set up Database mail.

EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'Emailer'
    ,@description = 'Email out reports'
    ,@email_address = 'XXXXXXX@XXXXXXX.com.au'
    ,@display_name = 'SA'
    ,@username = 'XXXXXXX@XXXXXXX.com.au'
    ,@password = '**********'
    ,@mailserver_name = 'smtp.office365.com'
    ,@replyto_address = 'XXXXXXXX@XXXXXXXX.com.au'
    EXECUTE msdb.dbo.sysmail_add_profile_sp
    @Profile_name = 'Emailer'
    ,@description = 'Email out reports'
    EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'Emailer'
    ,@accoun t_name = 'Emailer'
    ,@sequence_number = 1; 
    EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'Emailer'
    ,@principal_name = 'public'
    ,@is_default = 1;

    UPDATE msdb.dbo.sysmail_server
    SET enable_ssl = 1

This script works, and then once I've run the script I try and send an email using Database Mail. On one server the email works, on another server I get the error:

The mail could not be sent to the recipients because of he mail server failure. (Sending Mail using Account 1 (2015-08-21T11:27:55). 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.57 SMTP; Client was not authenticaed to send anonymous mail during MAIL FROM).)

What could be causing this?

  • First verify your credentials my guess is that it should be like @username = 'XXXXXXX@XXXXXXX.com' Second verify Port Number as for office365 port number is 587. Link may help you sqlcache.blogspot.com/2014/11/sql-server-database-mail.html – AA.SC Aug 21 '15 at 6:22
  • 1
    Yes I believe you'll need to add @port = 587 per the information here. If that doesn't work, do you get any further details in the Database Mail log if you enable verbose logging? – James Lupolt Aug 24 '15 at 6:36
  • Did you manage to find a solution to this problem? – Giorgos Betsos Jun 20 '17 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.