Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Use the Database Mail Configuration Wizard or the Database Mail stored procedures to create public Database Mail profiles. A public profile allows any user with access to the msdb database to send e-mail using that profile.
To create a Database Mail public profile using Transact-SQL
Create one or more Database Mail accounts for the profile. For more information about creating Database Mail accounts, see How to: Create Database Mail Accounts (Transact-SQL).
Execute the stored procedure msdb.dbo.sysmail_add_profile_sp to create the profile, specifying:
- The name of the profile to create.
- An optional description of the profile.
For each account, execute msdb.dbo.sysmail_add_profileaccount_sp to add the account to the profile.
Grant public access to the profile by executing msdb.sysmail_add_principalprofile_sp with 'public' as the @principal_name, or 0 as the @principal_id.
Example
The following example creates a Database Mail account and a Database Mail profile. The example then adds the account to the profile and grants access to the profile to all users in the msdb database.
-- Create a Database Mail account
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'AdventureWorks Public Account',
@description = 'Mail account for use by all database users.',
@email_address = '[email protected]',
@replyto_address = '[email protected]',
@display_name = 'AdventureWorks Automated Mailer',
@mailserver_name = 'smtp.Adventure-Works.com' ;
-- Create a Database Mail profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'AdventureWorks Public Profile',
@description = 'Profile used for administrative mail.' ;
-- Add the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'AdventureWorks Public Profile',
@account_name = 'AdventureWorks Public Account',
@sequence_number =1 ;
-- Grant access to the profile to all users in the msdb database
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'AdventureWorks Public Profile',
@principal_name = 'public',
@is_default = 1 ;
See Also
Tasks
How to: Create Database Mail Private Profiles (Transact-SQL)
Concepts
Other Resources
New Profile (Database Mail)
Select Configuration Task (Database Mail)
Database Mail Configuration Wizard
sysmail_add_account_sp (Transact-SQL)
sysmail_add_principalprofile_sp (Transact-SQL)
sysmail_add_profile_sp (Transact-SQL)