70 likes | 198 Views
Sql server. Database Mail. EXECUTE msdb.dbo.sp_send_dbmail @profile_name = ‘HRMail’, @recipients = ‘Gregory.House@adventureworks.com’, @copy_recipients = ‘Administrator@adventureworks.com’, @body = ‘Your data has been successfully imported!’,
E N D
Sql server Database Mail
EXECUTE msdb.dbo.sp_send_dbmail • @profile_name = ‘HRMail’, • @recipients = ‘Gregory.House@adventureworks.com’, • @copy_recipients = ‘Administrator@adventureworks.com’, • @body = ‘Your data has been successfully imported!’, • @subject = ‘Import Notification Message - Success’;
EXECUTE msdb.dbo.sp_send_dbmail • @profile_name = ‘HRMail’, • @recipients = ‘Lisa.Cuddy@adventureworks.com’, • @blind_copy_recipients = ‘Gregory.House@adventureworks.com; • Administrator@adventureworks.com’, • @body = ‘Per your request, here are the employees hired in 2002.’, • @query = ‘SELECT Person.Person.FirstName AS First, • Person.Person.LastName AS Last, • HumanResources.Employee.HireDate AS [Date of Hire] • FROM Person.Person INNER JOIN HumanResources.Employee • ON Person.Person.BusinessEntityID = HumanResources.Employee.BusinessEntityID • WHERE HireDate > ‘’2002-01-01" AND HIREDATE < ‘’2003-01-01’’ • ORDER BY HireDate’, • @execute_query_database = ‘AdventureWorks2008’, • @subject = ‘Employees Hired in 2002’, • @attach_query_result_as_file = 1;
Managing Messages • SELECT * FROM msdb.dbo.sysmail_mailitems • EXECUTE msdb.dbo.sysmail_delete_mailitems_sp • @sent_before = ‘January 31, 2009’ ; • EXECUTE msdb.dbo.sysmail_delete_mailitems_sp • @sent_status = ‘failed’;
sp_send_dbmail @profile_name, @recipients, @copy_recipients, @blind_copy_recipients, @subject, @body, @body_format, @importance, @sensitivity, @file_attachments, @query, @execute_query_ • Database, @attach_query_result_ • as_file, @query_attachment_ • filename