Question

I am attempting to use sp_send_dbmail to send out an attachment. The attachment is stored in a varbinary(MAX) column in a table. Here is my query:

EXEC msdb.dbo.sp_send_dbmail 
        @recipients='mick.walker@somewhere.com',
        @subject = 'Test Attachment',
        @body = 'Test',
        @body_format = 'HTML',
        @profile_name = 'intranetadmin',
        @query = 'Select DocumentData from [myDB].[dbo].[Documents] Where DocumentID = 8',
        @query_result_header = 0,
        @attach_query_result_as_file = 1,
        @query_attachment_filename = 'Test.pdf',
        @exclude_query_output = 1,
        @query_no_truncate = 0;

The email sends sucessfully with a pdf attachment. However when it comes to opening the attachment, I get an error. I think the size of the file is being truncated, even though I explicitaally state no to in my query.

I have checked the MAX allowed message size in the Database Mail settings and it is currently 104857600 bytes (100mb), the files I am attempting to send, are nowhere near this size - so I am a little puzzled.

Was it helpful?

Solution

I know this is an old thread but I have just come across the same issue. The problem is SQL reported an error and has stored the error message in the attachment.

Change the name of the attachment to have a .txt extension and send the email. Open the .txt file and view the error. It is probably something to so with a security configuration.

OTHER TIPS

Try setting @query_no_truncate parameter to 1. When large variable length data types are used in the query and this option is 0 or not specified data gets cut to 256 characters. Reference: http://msdn.microsoft.com/en-us/library/ms190307.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top