need to put script output into email body

  • Is it possible for the output of a script to be included in the body of an email created by the script? I'd prefer not to send it as an attachment that needs to be opened separately.

    Thanks in advance.

  • Here's an example of including the results of a query in the body of an email:

    exec msdb.dbo.sp_send_dbmail

    @profile_name = 'SQL Server Agent',

    @recipients = 'me@mycompany.com',

    @subject = 'Results of the query',

    @body = 'Check this out: ',

    @query = 'select ...,

    @query_result_header = 0,

    @query_result_width = 500,

    @exclude_query_output = 1

    See sp_send_dbmail in BOL for more arguments and examples.

    Greg

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply