SQL Server Database Mail Attachment Error

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


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'[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


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



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

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips


Article Last Updated: 2017-01-03

Comments For This Article




Friday, January 26, 2024 - 4:38:33 AM - mzwai Back To Top (91888)
Thanks, simple direct solution

Monday, March 21, 2022 - 10:38:47 PM - ck Back To Top (89910)
helpful contents!!!!
TQVM!!

Thursday, March 17, 2022 - 11:41:34 AM - Tiesto Back To Top (89898)
Thanks from Mexico

Friday, June 26, 2020 - 3:32:32 AM - rizki Back To Top (86050)

Thanks. This content is helpful.


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

Thanks -- well written!


Thursday, February 2, 2017 - 6:12:57 AM - Yelender Merugu Back To Top (45798)

Hi ranga,

 

Thank you for the post,

 

It is really helpful.















get free sql tips
agree to terms