How to: Create Database Mail Accounts (Transact-SQL)

Use the Database Mail Configuration Wizard or the Database Mail stored procedures to create Database Mail accounts.

For more information about Database Mail Configuration Wizard, see New Account (Database Mail).

To create a Database Mail account using Transact-SQL

  1. Determine the server name and port number for the Simple Mail Transfer Protocol (SMTP) server you use to send e-mail.

  2. If the SMTP server requires authentication, determine the user name and password for the SMTP server.

  3. Execute the stored procedure msdb.dbo.sysmail_add_account_sp to create the account, specifying:

    • The name of the account to create.

    • An optional description of the account.

    • The e-mail address to show on outgoing e-mail messages.

    • The display name to show on outgoing e-mail messages.

    • The server name of the SMTP server.

    • The user name to use to log on to the SMTP server, if the SMTP server requires authentication.

    • The password to use to log on to the SMTP server, if the SMTP server requires authentication.

Optionally, you may also specify the type of the server and the port number for the server. The server type is always 'SMTP' for outgoing mail. Most SMTP servers use port 25, the default.

Example

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' ;