How do I get size limits to work properly?

No mail system can process items of unlimited size, so limits need to be placed at various points in the mail system to shield your server hardware and software from having crucial resources consumed by oversized mail. There are several different limits you'll probably want to set:

1. Your upstream mail server (MTA) has the ability to reject items that exceed a certain size. This is an important limit because it offers you the ability to set a hard upper bound on the size of items your mail system will accept. In setting this value, you should keep in mind that some downstream portions of your mail system--such as your spam and virus filters--require a lot more resources than your mail server does to process a mail item of a given size, so even if your mail server can easily handle a 50 MB item, that item could choke your downstream resources and create serious delays in your mail system's throughput. By using the mail server's size limit as a "shield" for your downstream resources, you ensure that your mail system's throughput remains at a level that you can live with.

For Postfix, set message_size_limit (in bytes) in your file:

message_size_limit = 10000000

To do the same with Sendmail, add confMAX_MESSAGE_SIZE to your file and re-run your M4 processor:


2. SpamAssassin consumes a lot of system resources to scan a mail item, which is not surprising given that it tests the mail against 800+ rules and network tests. The larger the mail item, the longer it takes, of course, and this is not a linear relationship, it's exponential--you do not want to waste system resources spam-checking huge mail items, particularly since almost all spam is relatively small in size. Spammers make their money by sending out as many mail items as they can in a short amount of time, so sending large items only slows them down. The upshot for you is that you can pretty safely tell SpamAssassin to ignore items larger than, say, 256 kB, since they're statistically unlikely to be spam. Doing this saves you precious system resources, even if it technically creates a loophole through which a spammer could bypass your filter.

You'll want to set this in two places: in your amavisd.conf file (so that amavisd-maia will not call SpamAssassin when the mail item is too large), and in your maia.conf file (so that Maia's script will not call SpamAssassin to report or train on overly-large mail items).

In your amavisd.conf file:

$sa_mail_body_size_limit = 256*1024; # don't waste time on SA if mail is larger

In your maia.conf file:

$default_max_size = 256*1024;

3. For the purpose of quarantining and caching mail items, Maia needs to store these items in a database. The database software itself, however, may have some limits on how large an item can be stored in one of its columns. PostgreSQL's TEXT data type can theoretically hold an item of unlimited size, subject to the storage limits of your disk. MySQL's LONGTEXT data type is limited to 4 GB. MySQL users must also set the max_allowed_packet variable to the size of the largest item (up to 4 GB) that they wish to store in the database (note that the default is 1 MB, which is rather small).

In your my.cnf file:


4. As you can imagine, with one size limit set at the upstream mail server and one required for the database, we need a way to decide how to handle the items that fall in between. For example, suppose that you set your database size limit to 10 MB, but your upstream mail server accepts mail as large as 20 MB. What happens to a 15 MB e-mail? Maia provides one more size limit feature on its System Configuration page, which lets you set a cut-off point for oversized items--items that have been accepted by the upstream mail server, but which should not be scanned, filtered, or quarantined in any way. You can then tell Maia whether items larger than this size should be automatically accepted (delivered) or rejected with a brief message explaining the size limit.

These settings can be found on Maia's System Configuration page:

Mail size limit (bytes):      [15000000] 	
Oversized items should be...  [x] Accepted  [ ] Rejected

The relationship between these various size limits is important, of course. If A is the upstream mail server's size limit, B is MySQL's size limit (i.e. max_allowed_packet), C is Maia's size limit, and D is SpamAssassin's size limit, then the only relationship that makes sense is:

A >= B > C >= D

Back to FAQ

Last modified 14 years ago Last modified on Apr 25, 2006, 8:19:25 PM