By: Ranga Babu | 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:
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.
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.
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.
Another option that we can change is the Prohibited Attachment File Extensions. This will allow us to block specific file extensions as attachments.
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 about Database Mail.
About the author
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