Creates a new Database Mail account holding information about an SMTP account.
sysmail_add_account_sp [ @account_name = ] 'account_name', [ @email_address = ] 'email_address' , [ [ @display_name = ] 'display_name' , ] [ [ @replyto_address = ] 'replyto_address' , ] [ [ @description = ] 'description' , ] [ @mailserver_name = ] 'server_name' [ , [ @mailserver_type = ] 'server_type' ] [ , [ @port = ] port_number ] [ , [ @username = ] 'username' ] [ , [ @password = ] 'password' ] [ , [ @use_default_credentials = ] use_default_credentials ] [ , [ @enable_ssl = ] enable_ssl ] [ , [ @account_id = ] account_id OUTPUT ]
Database Mail provides separate parameters for @email_address, @display_name, and @replyto_address. The @email_address parameter is the address from which the message is sent. The @display_name parameter is the name shown in the From: field of the e-mail message. The @replyto_address parameter is the address where replies to the e-mail message will be sent. For example, an account used for SQL Server Agent may send e-mail messages from an e-mail address that is only used for SQL Server Agent. Messages from that address should display a friendly name, so recipients can easily determine that SQL Server Agent sent the message. If a recipient replies to the message, the reply should go to the database administrator rather than the address used by SQL Server Agent. For this scenario, the account uses SqlAgent@Adventure-Works.com as the e-mail address. The display name is set to SQL Server Agent Automated Mailer. The account uses danw@Adventure-Works.com as the reply to address, so replies to messages sent from this account go to the database administrator rather than the e-mail address for SQL Server Agent. By providing independent settings for these three parameters, Database Mail allows you to configure messages to suit your needs.
The @mailserver_type parameter is provided for flexibility in future releases. SQL Server 2005 and later supports the value 'SMTP' for @mailserver_type.
When @use_default_credentials is 1 mail is sent to the SMTP server using the credentials of the SQL Server Database Engine. When @use_default_credentials is 0 and a @username and @password are specified for an account, the account uses SMTP authentication. The @username and @password are the credentials the account uses for the SMTP server, not credentials for SQL Server or the network that the computer is on.
The stored procedure sysmail_add_account_sp is in the msdb database and is owned by the dbo schema. The procedure must be executed with a three-part name if the current database is not msdb.
The following example creates an account named AdventureWorks Administrator. The account uses the e-mail address dba@Adventure-Works.com and sends mail to the SMTP mail server smtp.Adventure-Works.com. E-mail messages sent from this account show AdventureWorks Automated Mailer on the From: line of the message. Replies to the messages are directed to danw@Adventure-Works.com.
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' ;