Blog di Zanirato Luca

Microsoft SQL Server Database!

Blog - Sites Links

Configuration SQL Server Database_Mail

Per configurare Database_Mail procedere come segue :

1) Impostazione Account Database_Mail

EXECUTE msdb.dbo.sysmail_add_account_sp 
        @account_name = ' ',
        @description = ' ' ,
        @email_address = ' ' ,
        @display_name = ' ',
        @username = ' ' ,
        @password =' ',
        @mailserver_name = ' '


2) Impostazione Profilo Database_Mail

EXECUTE msdb.dbo.sysmail_add_profile_sp
        @profile_name = ' ' ,
        @description = 'Profile used for database mail'


3) Aggancio Profilo / Account Database_Mail

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
        @profile_name = ' ' , (stesso nome messo nel punto 2)
        @account_name = ' ' , (stesso nome messo nel punto 1)
        @sequence_number = 1


4) Impostazione Profilo Principale

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
        @profile_name = ' ' , (stesso nome messo nel punto 3)
        @principal_name = ' ' ,
        @is_default = 1 ;


Una volta effettuata la configurazione testiamo il tutto :


TEST Invio Mail

DECLARE @body1 VARCHAR(100)
SET @body1 = 'Server :'+@@servername+ ' My First Database Email !'
EXEC msdb.dbo.sp_send_dbmail
       @recipients= ' ' ,
       @subject = ' ' ,
       @body = @body1,
       @body_format = ' ' ;


Se si vuole impostare la notifica d'errore al Job, nel caso avvenga un errore durante

la sua esecuzione, aggiungere un nuovo step con il seguente codice :


EXEC msdb.dbo.sp_send_dbmail
        @profile_name = ' ' ,
        @recipients = ' ' , (E' possibile aggiungere più account separati da ";")
        @body = ' ' ,
        @subject = ' ' ;


Ciao a tutti Wink

Posted: mag 20 2009, 11.52 by superzani3 | with no comments |
Filed under: