Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

SQL Server Database Mail Attachment Error


By:   |   Read Comments (1)   |   Related Tips: More > Database Mail

New Whitepaper > 10 Ways We Can Steal Your Data >> download now


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:

file attachment or query results size exceeds allowable value

 

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.

Check the SQL Server Database Mail properties with sysmail_help_configure_sp

 

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.

Change SQL Server Database Mail Settings with Management Studio

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.

SQL Server Database Mail Attachment Size

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

SQL Server Database Mail Prohibited Attachment File Extensions

 

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


Last Update:


signup button

next tip button



About the author
MSSQLTips author Ranga Babu Ranga Babu is a SQL Server DBA with experience on performance tuning and high availability.

View all my tips
Related Resources





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Notify for updates 


SQL tips:

*Enter Code refresh code     



Thursday, February 02, 2017 - 6:12:57 AM - Yelender Merugu Back To Top

Hi ranga,

 

Thank you for the post,

 

It is really helpful.


Learn more about SQL Server tools