5.7.1 SMTP error when running stored proc using DB Mail in SQL Server 2012

5,067

To fix this issue I have installed a SMTP server locally on the same server as the SQL Server instance. I configured DB mail to localhost then set the Office 365 settings in the SMTP server ensuring that TLs encryption and the correct port is stated.

This seemed to fix the issue for me.

Share:
5,067

Related videos on Youtube

medina
Author by

medina

Updated on September 18, 2022

Comments

  • medina
    medina over 1 year

    I am getting an error in SQL Server 2012 Database Mail when executing a stored proc to send an email from a specified address to a specified address using Office 365 as the SMTP server.

    The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2014-06-10T15:28:48). Exception Message: Cannot send mails to mail server. (Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender).

    This same stored proc is working in production on another server fine. The only change is that this instance of the working stored proc is SQL Server 2008 R2.

    Judging from the error this is a SMTP error, am I correct? All users I am using to send and receive the mail are in the same O365 domain and have {SendAs} access rights and NT Authority\Self Trustees in O365.

    I can telnet office 365 over the specified port (587) fine and even stranger is I can send email using the 'Send Test E-Mail' feature in DB Mail fine using the same Office 365 profile that is specified in the stored proc.

    Any help would be appreciated.

    Screenshot of database mail settingsenter image description here

    • Admin
      Admin almost 10 years
      Could you post your SQL Server SMTP Relay configuration (obfuscate what is sensitive)?
    • medina
      medina almost 10 years
      @SujaySarma screenshot in edit of post
    • Admin
      Admin almost 10 years
      Are you able to logon as this ([email protected]) user in the Outlook Web Access for your O365 account and send out email?
    • medina
      medina almost 10 years
      @SujaySarma Yes. This email address is working with identical configs in SQL Server 2008 R2 on another server. I can even send a test email in database mail using the profile in the screenshot. However I get a 5.7.1 error when I execute the query to send email using this db mail profile.
    • Ryan Ferretti
      Ryan Ferretti almost 10 years
      Are you sure this is the only account on the server?
    • medina
      medina almost 10 years
      @mrdenny yes this is the only account and profile on the server.