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)
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
EXEC msdb.dbo.sp_send_dbmail
@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.
source
share