SQL Server SP_SEND_DBMAIL Image File Attachment

I am using a trigger in a table to send email using sp_send_dbmail.

I want to include a file attachment in an image type email.

The raw data for jpeg is stored in the ndl_Image column, which is a binary type.

I have the following code: -

DECLARE @ReferenceID varchar(max)
DECLARE @Recipient varchar(Max)
DECLARE @Body varchar(max)
DECLARE @Subject varchar(max)
DECLARE @Q varchar(max)

--Get the EntryId and FormID for the inserted data.
SET @ReferenceID = 40
SET @Recipient = (SELECT ndl_CategorySendTo FROM ndl_config WHERE ndl_CategoryName = 'Dead Animal')
SET @Body = '<html>A new request has been created.</html>'
SET @Subject = 'NDL Report It: New Request #'+@ReferenceID
SET @Q = 'SELECT ndl_Image from dbo.ndl_data where ndl_ID ='+@ReferenceID
--Execute the stored procedure to send mail.
EXEC msdb.dbo.sp_send_dbmail

--Pass it the following paramaters.
@recipients=@Recipient,
@body=@Body, 
@subject=@Subject,
@profile_name='NDLProfile',
@body_format ='HTML',
    @execute_query_database='NDL_MX',
@query = @Q,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'image.jpg'

This works fine, but it seems to return the request as a text file if I comment on the last line.

How can I get the attachment as a jpeg file ????

Thank.

+4
source share
1 answer

I do not think that's possible. As stated in the documentation for SP_SEND_DBMAIL :

" , set . ." [ ]

0

All Articles