• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3100
  • Last Modified:

I need to set message size limit for outgoing/incoming mail separately

I am trying to set the message size limit for outgoing/incoming mail separately so internal users can only send messages no larger than 2Mb but be able to receive messages up to 10Mb.
Is there any way to do it?.

I am using

postfix as MTA and courierimap
Ludwig Diehl
Ludwig Diehl
  • 3
  • 2
  • 2
  • +4
2 Solutions
imkotteesSenior Messaging EngineerCommented:
Ludwig DiehlSystems ArchitectAuthor Commented:
Thx for the quick response. Indeed I actually read that article before posting my question here. The problem is that my main.conf file has these settings:

mailbox_size_limit = 0
message_size_limit = 2097152

But it limits both, incoming and outgoing messages to 2Mb. I only want to set 2Mb limit for outgoing messages and 10Mb for incoming.
imkotteesSenior Messaging EngineerCommented:
i'm sorry. i could not find on the web. I'm a beginner :(
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Ludwig DiehlSystems ArchitectAuthor Commented:
no prob. Thx for trying anyway ;)
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
Backup your main.cf file, then edit:

message_size_limit = 10240000

restart postfix
Ludwig DiehlSystems ArchitectAuthor Commented:
thx for your reply. Unfortunately what I need is to limit the outgoing message size to 2Mb and the incoming message size to 10Mb. So users cannot send messages above 2Mb nor receive messages above 10Mb.
If I try your solution it will limit both incoming/outgoing messages to 9.77Mb.
Gerwin Jansen, EE MVETopic Advisor Commented:
I'm thinking that message_size_limit is only influencing the max size of messages on your postfix mail server (both in and out). This is what you want to set to 10Mb. Now about sending messages: your remote MTA should be configured not to accept messages larger than 2Mb. So you'd either have to setup a second postfix instance that you send through (configured for a message_limit of 2Mb) or have someone configure the remote MTA for you.
message_size_limit is a global size limit, this is because Postfix is an MTA rather than a "mailbox server" such as Exchange.

If your postfix server is behind NAT and you have two public IP addresses, use one address for mx.domain.com which is configured as your MX record and the other as mail.domain.com which is the address that your mail clients use.

The actual server still only needs one address.

Use PAT to forward inbound port 25 for mx.domain.com to a "high" port running on Postfix (with a 10mb limit) , this delivers to your users "mailboxes"

Use PAT to forward port 25 on mail.domain.com to port 25, where you have either another instance of Postfix, or qmail/sendmail/exim etc, and here you have a 2mb limit, this instance of Postfix is setup just as an MTA, with all inbound mail forwarded to the other instance of Postfix running on the high port, it should NOT be configured to deliver to your users "mailboxes" having two email servers pointing at the same place can lead to  corruption of email.

You should now have a mail server that will accept inbound mail of 10mb, while restricting users to 2mb.
Postfix size limits are a global setting.  Depending on where you are in your deployment, there may be some options.  My suggestion would be to  edit /etc/postfix/master.cf

Setup an additional listening service on a different port;  For example, port 587 is commonly used for mail submission.

Either use a separate IP address that you publish in MX, that is different from the IP address your local users are allowed to use;

Or Disable relay on Port 25,  or allow SMTP authentication only on port 587, and force local users to use port 587;  with port 25 for incoming mail only.

Or Use iptables  DNAT  or  redirect rules,  to divert TCP  connections from local IP addresses to port 587.

For example, a   /etc/postfix/master.cf   entry might  contain things like inet    n    -    y    -    -    smtpd
-o message_size_limit=2097152
-o smtpd_recipient_limit=200
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_sender_restrictions = reject_unlisted_sender,reject_sender_login_mismatch,permit_mynetworks,reject
 -o soft_bounce=no
 -o smtpd_helo_required=no
 -o bounce_notice_recipient=postmaster
 -o smtpd_client_connection_count_limit=20
 -o smtpd_helo_restrictions=
 -o smtpd_recipient_restrictions=permit_mynetworks,reject
 -o mynetworks=,
 -o strict_rfc821_envelopes=no
 -o smtpd_error_sleep_time=0
 -o smtpd_soft_error_limit=1001
 -o smtpd_hard_error_limit=1000
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
User properties
Check this limits

- Rancy
@Rancy, this is on Postfix, not Exchange
Although Postfix does not support per-sender limits, or applying a different limit to certain IPs;

Another option is to configure Postfix to the _highest_ limit you ever use, and implement  a Content filter,  Policy daemon, or before-queue Milter plugin,  
to enforce lower limits when required.

Such as

See here, about Postfix support for Milter plugins:

It may be more useful to use CBPolicyd
and set an  _aggregate_   number of megabytes transferred per user quota, than a per-message quota.

For example:  "Each user can send up to a rolling average of 20 Megabytes of messages per day"

That could be   up to  10    2 Megabyte messages,
or up to 20  1 Megabyte messages,
up to 40  500 kilobyte messages,

up to 80  250 kilobyte messages,
or up to 160 125 kilobyte messages,
for example.

In other words:  An aggregate quota prevents users from defeating the  1 Megabyte size limit anymore to send  a  2 Gigabyte file,  by   splitting that big file into   2000  separate e-mails, and sending all those e-mails out.

Which (IMO)  is a little bit more useful than simply limiting to 1MB.
Although the 1MB limit will definitely remain useful for low-bandwidth WANs,
as it  provides a limitation of the total SMTP session delay, and therefore,
helps eliminate one situation that can cause very poor mail server performance.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now