Nasıl Yapılır: Veritabanı posta Public Profiles (Transact-SQL) oluşturma

Ortak bir veritabanı posta profili oluşturmak için veritabanı Adres Yapılandırma Sihirbazı'nı veya veritabanı posta depolanmış yordamlar kullanın.Ortak Profil erişimi olan herhangi bir kullanıcı sağlar msdb veritabanı bu profili kullanarak e-posta göndermek için.

Transact-SQL kullanarak bir veritabanı posta ortak profil oluşturmak için

  1. Profil için bir veya daha çok veritabanı posta hesabı oluşturun.Veritabanı posta hesapları oluşturma hakkında daha fazla bilgi için bkz: Nasıl Yapılır: Veritabanı posta hesapları'nı (Transact-SQL) oluştur.

  2. Saklı yordam Çalıştır msdb.dbo.sysmail_add_profile_sp, profil oluşturmak için belirtme:

    • Oluşturulacak profilin adını.

    • Profil isteğe bağlı bir açıklaması.

  3. Her hesap için yürütmek msdb.dbo.sysmail_add_profileaccount_sp profile hesabı eklemek için.

  4. Ortak Profil yürütmek yoluyla erişim msdb.sysmail_add_principalprofile_sp with 'public' as the @ principal_name, or 0 as the @ principal_id.

Example

Aşağıdaki örnek, bir veritabanı posta hesabı ve bir veritabanı posta profili oluşturur.Örnek sonra hesabın profile ekler ve tüm kullanıcıların profile erişim verir msdb veritabanıdır.

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