SQL Server includes Database Mail (it was a new feature released back in 2005 as a replacement for SQL Mail). Database Mail is a great feature as it allows:
❌ Figure: Bad example - Using SQL Mail
EXEC master.dbo.xp_smtp_sendmail@FROM_NAME = N'Sophie Belle',@subject = 'Vendor List',@message = 'The list of vendors is attached.',@type = N'text/html',@server = N'mail.company.com.au'
❌ Figure: Bad example - Avoid using SQL Mail - you need to have Outlook on the server and there is no built-in logging
✅ Figure: Good example - Use Database Mail
USE msdbExecute dbo.sp_send_dbmail@profile_name = 'UTS',@body = 'The list of vendors is attached.',@query = 'USE AdventureWorks; SELECT VendorID, Name FROM Purchasing.Vendor',@subject = 'Vendor List',@attach_query_result_as_file = 1
✅ Figure: Good example - Use database mail for scalability, built-in logging and HTML capability