SQL Server Database Mail Attachment Error

By:   |   Updated: 2017-01-03   |   Comments (2)   |   Related: More > Database Mail


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?


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'[email protected]',
   @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 Updated: 2017-01-03

get scripts

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

More SQL Server Solutions

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 (*).

Email me updates

Signup for our newsletter

I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.

Thursday, February 28, 2019 - 10:43:24 AM - jk Back To Top

Thanks -- well written!

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

Hi ranga,


Thank you for the post,


It is really helpful.


Recommended Reading

Setup SQL Server Database Mail to use a Gmail, Hotmail, or Outlook account

Send email in a tabular format using SQL Server database mail

Setting up Database Mail for SQL Server

Generate HTML Formatted Emails from SQL Server

Troubleshooting SQL Server sp_send_dbmail Error Failed to Initialize SQLCMD Library

get free sql tips
agree to terms

Learn more about SQL Server tools