Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Configure configs
- --
- USE [master];
- GO
- sp_configure
- 'show advanced options',
- 1;
- GO
- RECONFIGURE WITH OVERRIDE;
- GO
- sp_configure
- 'Database Mail XPs',
- 1;
- GO
- RECONFIGURE;
- GO
- --
- -- Creating account
- --
- EXECUTE msdb.dbo.sysmail_add_account_sp
- @account_name='<account_name, nvarchar(100), Account>',
- @description='Mail account for Database Mail',
- @email_address='<email_address, nvarchar(100), email@domain.com>',
- @display_name='Account',
- @username='<username, nvarchar(100), email@domain.com>',
- @password='<password, nvarchar(100), ********>',
- @mailserver_name='<mailserver_name, nvarchar(100), smtp.gmail.com>',
- @port='<port, int, 587>';
- GO
- --
- -- Creating profile
- --
- EXECUTE msdb.dbo.sysmail_add_profile_sp
- @profile_name='<profile_name, nvarchar(100), Profile>',
- @description='Profile needed for database mail';
- GO
- --
- -- Creating profile account
- --
- EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
- @profile_name='<profile_name, nvarchar(100), Profile>',
- @account_name='<account_name, nvarchar(100), Account>',
- @sequence_number=1;
- GO
- --
- -- Defining principal profile
- --
- EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
- @profile_name='<profile_name, nvarchar(100), Profile>',
- @principal_name='public',
- @is_default=1;
- GO
- --
- -- Sending...
- --
- DECLARE
- @guid NVARCHAR(MAX)=NEWID( );
- DECLARE
- @body1 VARCHAR(100);
- SET @body1='Server: '+@@servername+' Test DB Email - Id :'+@guid;
- EXEC msdb.dbo.sp_send_dbmail
- @recipients='<recipients, nvarchar(100), recipient@domain.com>',
- @subject='Test',
- @body=@body1,
- @body_format='HTML';
- SELECT *
- FROM msdb.dbo.sysmail_event_log;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement