SQL database mail configuration to use a domain account that is not the SQL Service account

dba.stackexchange https://dba.stackexchange.com/questions/271969

سؤال

We have been asked to use a domain service account for everything releated to email (smtp). I looked at the SQL Database Mail and the only option that looked like Windows Auth. is the first one:

enter image description here

The problem is that the account we will use will not be the SQL service account.

Is there a way to make it work with a domain service account that is not the SQL Service account ?

هل كانت مفيدة؟

المحلول

Using Database Mail Configuration Wizard

You can achieve that by selecting the Basic authentication option and filling the user name in the Domain\Login format:

Configuration Wizard

You can check the New Account Page doc to understand each parameter of the wizard.

Using Transact-SQL

You can also use the system stored procedure sysmail_add_account_sp to do that. Here I used the example from the doc and added the last three parameters that are related to your question:

EXECUTE msdb.dbo.sysmail_add_account_sp  
    @account_name = 'AdventureWorks Administrator',  
    @description = 'Mail account for administrative e-mail.',  
    @email_address = 'dba@Adventure-Works.com',  
    @display_name = 'AdventureWorks Automated Mailer',  
    @mailserver_name = 'smtp.Adventure-Works.com', 
    @username = 'Domain\Login',
    @password = 'yourPassWord',
    @enable_ssl = 1;

Security Implication

Notice that on both examples I'm using the SSL option because, as Dan Guzman pointed out, the use of that option

Specifies whether Database Mail encrypts communication using Secure Sockets Layer

as you'll see in the doc. So, if you're not using a secure connection in your environment, those credentials, along with the email content, are gonna be sent in plain text to the SMTP mail server, therefore being a security issue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى dba.stackexchange
scroll top