locked
How to send an HTML file as body using database mail? RRS feed

  • Question

  • Hi All,

    Is there a way to send an existing HTML file as body of my email instead sending it as attachment.
    I am using below query, but it is sending as an attachment. Any workaround for this?


    EXEC msdb.dbo.sp_send_dbmail
          @profile_name = 'TestProfile',
          @recipients = 'abcd@gmail.com',
          @body_format = 'HTML',
          @subject = 'Test Email',
          @file_attachments='G:\MySalesReport.htm',
          @attach_query_result_as_file = 0 ;
        
    Thanks in Advance.
    • Moved by Olaf HelperMVP Monday, March 7, 2016 4:06 PM Moved from "Database Engine" to a more related forum
    Wednesday, January 20, 2016 6:42 PM

Answers

  • Your HTML goes in the @body parameter, not the @file_attachment parameter.

    I know, it is disappointing.  You have to form the HTML yourself.  Or read your HTM file, and stuff it into a varchar(max) datatype parameter, then assign this parameter to @body in the sp_send_dbmail sproc.


    -- Paul Wehland (MCM-SQL) Avanade GmbH

    Wednesday, January 20, 2016 9:45 PM