This script assumes you have set up database mail with an account name of 'SQL Administrator' and provided valid SMTP details.
-- declare variables DECLARE @chvFrom VARCHAR(255) DECLARE @chvTo VARCHAR(255) DECLARE @chvSubject VARCHAR(255) DECLARE @chvBody VARCHAR(8000) -- set values SET @chvFrom = 'SQLAdmin@mydomain.net' SET @chvTo = 'recipient@mydomain.net' SET @chvSubject = 'Test email from ' + @@SERVERNAME SET @chvBody = 'test body text' -- send the mail EXEC msdb.dbo.sp_send_dbmail @profile_name='SQL Administrator', @recipients=@chvTo, @body=@chvBody,@subject=@chvSubject, @importance='High'
No comments:
Post a Comment