SQL Server provides us with the ability to send emails via its Database Mail solution. This includes a bunch of stored procedures that facilitate the configuration and sending of emails.
To send an email, use the sp_send_dbmail
stored procedure. This procedure accepts a bunch of optional arguments, one of which allows you to send attachments.
Actually, there are two arguments that enable you to send attachments. The one you use will depend on the context.
They are:
@file_attachments
– Allows you to specify a file to attach to the email.@attach_query_result_as_file
– This is only applicable if you’re also using@query
to email the results of a query.
Examples below.
Continue reading