Vorgehensweise: Erstellen öffentlicher Profile für Datenbank-E-Mail (Transact-SQL)

Verwenden Sie den Assistenten zum Konfigurieren von Datenbank-E-Mail oder gespeicherte Prozeduren von Datenbank-E-Mail, um öffentliche Datenbank-E-Mail-Profile zu erstellen. Mit einem öffentlichen Profil kann jeder Benutzer mit Zugriff auf die msdb-Datenbank E-Mail mithilfe dieses Profils senden.

So erstellen Sie ein öffentliches Profil für Datenbank-E-Mail mithilfe von Transact-SQL

  1. Erstellen Sie mindestens ein Datenbank-E-Mail-Konto für das Profil. Weitere Informationen zum Erstellen von Konten für Datenbank-E-Mail finden Sie unter Vorgehensweise: Erstellen von Konten für Datenbank-E-Mail (Transact-SQL).

  2. Führen Sie die gespeicherte Prozedur msdb.dbo.sysmail_add_profile_sp aus, um das Profil zu erstellen, und geben Sie Folgendes an:

    • Den Namen des zu erstellenden Profils.

    • Eine optionale Beschreibung des Profils.

  3. Führen Sie für jedes Konto msdb.dbo.sysmail_add_profileaccount_sp aus, um dem Profil das Konto hinzuzufügen.

  4. Erteilen Sie öffentlichen Zugriff auf das Profil, indem Sie msdb.sysmail_add_principalprofile_sp mit 'public' als @principal_name ausführen, oder mit 0 als @principal_id.

Beispiel

Im folgenden Beispiel wird ein Datenbank-E-Mail-Konto und ein Datenbank-E-Mail-Profil erstellt. Dann wird das Konto dem Profil hinzugefügt, und allen Benutzern in der msdb-Datenbank wird Zugriff auf das Profil gewährt.

-- 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 = 'db_users@Adventure-Works.com',
    @replyto_address = 'danw@Adventure-Works.com',
    @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 ;