Blog Pages

SQL Server Email Alerts Notifications

--********************************
--Definitions: Run once
--********************************
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'MyMailAccount',
    @description = 'Mail account for Database Mail',
    @email_address = 'XXXX@aaa.co.il',             --Replace
    @display_name = 'MyAccount',   
    @username='XXXX@aaa.co.il',                    --Replace
    @password='XXXX',                                 --Replace
    @mailserver_name = 'webmail'                      --Replace
GO

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

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'MyMailProfile',
    @account_name = 'MyMailAccount',
    @sequence_number = 1
GO

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'MyMailProfile',
    @principal_name = 'public',
    @is_default = 1 ;
GO

--********************************
--Execution: enter into SP
--********************************
EXEC msdb.dbo.sp_send_dbmail @recipients='XXXX@aaa.co.il',
    @subject = 'My Mail Test',
    @body = 'My First Database Email ',
    @body_format = 'HTML' ;

No comments:

Post a Comment