Complete Virtual Mail Server/Refining the Setup

Introduction
Now that there is a working secure server setup, or if it was decided to split services between various servers, secure servers setup, it is time to refine the setup by tweaking the postfix configuration.

Backup MX
Serving mail for domains is one thing, but what if a secondary server is setup, which is recommended, to serve as a backup? Or what if there are domains that are not hosted but it would be nice to serve as a backup for? Postfix has a feature specifically for this. Also the database already contains fields for this in in the domain table, so all that is required is to tie them into postfix is to edit. First a file needs to be created to store connection information.

Then some data needs to be added to the database.

Finally tell postfix to use the database for relayed domains, and to allow reception of backup domains.

After restarting postfix, postfix will accept mail for backupdomain.com and try to deliver it for as long as it can.

Introduction
Quotas are a tool to help a user monitor their mailbox. They are very easily abused and should not be relied on. That said, they can work well enough most of the time and give the user feedback on the status of his usage pattern. IMAP supports quota reporting and thus the mail-client can even report this the user. Thunderbird does this via an extension, roundcube shows this per default.

Configuration
The database supports mail quotas however postfix requires a patch to support these mailquotas. The patches postfix to allow the use of quotas.

Postfix requires certain changes and a way of accessing the database, as previously a new file is created to tell postfix where and how to get information on quotas.

Next postfix needs to be told that the virtual accounts use quotas. This is done in the configuration file.

Testing
Roundcube displays diskusage per default and hovering over it displays detailed information. Thunderbird has an extension, Display quota. For both and others to actually work a maildirsize file is required. This file will be created and updated whenever postfix delivers a message or when courier-imap makes chances. The file is located in each virtual users root mail dir, which would be in the case of testuser on example.com. Thus sending a message to testuser@example.com would create this file in the users maildir.

HELO Restrictions
Hackers, spammers and everybody else can obtain information from the mailserver by using the HELO and EHLO commands. Spammers usually put fake information in the HELO greeting and thus restricting and rejecting connections from servers that do not properly identify themselves can only be good. Postfix offers the smtpd_helo_restrictions variable to tune how to respond to connections. Restrictions here have to be thought over carefully however. Locking down the server too tight may make it so messages are rejected because the other server is just poorly configured. Use with regression. A quick overview of the available options. smptd_helo_restrictions overview The following table should give an idea how mail will get rejected from the various restrictions. An X mens the message will be rejected, the ? means it depends on the proper DNS record setup for that domain and O means the message will be delivered normally. smtpd_helo_restrictions table

On a properly configured network the following will be tight and should work.

Deny requesting local users
Normally postfix, or general MTA's allow to verify whether a mailbox exists or not. This command may have been useful in the early days of mail, but is almost exclusively used by peole who maintain bulk mailing lists and search if accounts are still valid. This command can be disabled by postfix.

After a restart of postfix, telnet to port 25 will no longer show 250-VRFY.

SMTPD Banner
Another oftenly abused feature is the SMTP header. Also some countries require senders to honor the NO UCE greeting message (No Unsolicited Commercial E-mail). Also it is wise not to tell any outsiders what MTA is being used or what version thereof. Postfix allows for changing the SMTP header quite easily. Find the smptd_banner section in the file and modify it accordingly.

Message size
For years the default message size amongst MTA's has been 10MB. Google raised the bar with their gmail service to 20MB per message. If bandwidth isn't an issue this can easily be accomplished with postfix.

A quick telnet to port 25 using the EHLO command should print 250-SIZE 20480000 after a postfix restart.

Postfix performance
For compatibility reasons postfix's local mail notification is enabled by default. With many users this can be a performance drain and since there are no local users to use the biff command anyway this can safely be disabled.

Processes
The amount of concurrent processes of any of postfix's applications is limited to 50. The first bump in high load environments can be very quickly be the amount of active daemons. Smaller setups should not need to worry about this setting.

DNS Lookup
A common throughput limiter is the use of DNS lookups. These can be slow and can be an issue far before processes, CPU or memory are the issue. One lookup per message is required at the very least per message, a server MX record needs to be found. A local caching DNS server could help enormously here and packages such as or even a full  setup should be used.

Mail storage
Postfix maintains a number of queue directories in. Various postfix applications pass messages around each other using these queues. Placing these directories on a separate disk, raid array or an SSD can significantly improve overall throughput. Also making sure that the partition in question is marked with the noatime option helps a lot o disk access. Postifx does not use access timestamps.

Multiple mail servers
If one server is not enough, multiple mail-servers can spread the load. Also having multiple mail-servers offers redundancy so it is something worth considering. spreading the load over several mail-servers can be done effectively using DNS round-robining. Two options are available here, either assign multiple A entries to the mail-server, or cleaner, have multiple MX entries which allow prioritization.