Quantcast
Viewing all articles
Browse latest Browse all 3160

SQL Server Database Mail Attachment Error

Problem

We setup SQL Server Database Mail and use it to send alerts via email. We recently received the following error "File attachment or query results size exceeds allowable value of 1000000 bytes." when sending an attachment in the email. How can this be fixed?

Solution

Here is an example of trying to send a large Excel file and getting the error message "file attachment or query results size exceeds allowable value".

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'test',
@recipients = N'test@test.com',
@subject = 'Large Attachment Error',
@body = '',
@file_attachments = 'largefile.xls'

When this code runs, it returns the following error:


Image may be NSFW.
Clik here to view.
SQL Server Database Mail Attachment Error

Check SQL Server Database Mail Settings

We can check the SQL Server Database Mail parameter properties by running the following stored procedure: sysmail_help_configure_sp .

exec msdb.dbo.sysmail_help_configure_sp

This stored procedure returns the SQL Server Database Mail parameters and parameter values.


Image may be NSFW.
Clik here to view.
SQL Server Database Mail Attachment Error

Change SQL Server Database Mail Settings with Management Studio

We can also check the settings using SQL Server Management Studio (SSMS). Go to Management > Database Mail and right click and select Configure Database Mail. Select Next until you get to the Select Configuration Task screen and select View or change system parameters and select Next.


Image may be NSFW.
Clik here to view.
SQL Server Database Mail Attachment Error

Here we can see the current setting for Maximum File Size (Bytes) . The default is 1,000,000 bytes which is 1MB. The maximum value we can use 2,147,483,647, which is roughly 2GB. If we try to use a value greater than 2147483647 it will throw an error. So change the value to the necessary size for your needs.


Image may be NSFW.
Clik here to view.
SQL Server Database Mail Attachment Error

Another option that we can change is the Prohibited Attachment File Extensions . This will allow us to block specific file extensions as attachments.


Image may be NSFW.
Clik here to view.
SQL Server Database Mail Attachment Error

Change SQL Server Database Mail Settings with T-SQL

We can also change these parameter values using sysmail_configure_sp as follows.

exec msdb.dbo.sysmail_configure_sp 'MaxFileSize','2000000'
exec msdb.dbo.sysmail_configure_sp 'ProhibitedExtensions','exe,dll,vbs,js,ps' Next Steps Read these additional tips aboutDatabase Mail. Last Update: 1/3/2017

Viewing all articles
Browse latest Browse all 3160

Trending Articles