Tuesday 11 March 2008

Installing Postfix SMTP server

Actually I installed Postfix before installing Dovecot. However, it took some tweaking to get dovecot running.

By default, postfix installs inboxes into /var/mail in a flat file format. This disallows creation of folder structures in the INBOX. I also run several domains on one server. It is simple to tell postfix to accept any combination of username@domain_x. In operation, this will lead to combinations that are certainly not desirable.

To fix this, I had to set up some domains as virtual domains in /etc/postfix/main.cf:
virtual_alias_domains = my.domain
virtual_alias_maps = hash:/etc/postfix/virtual
I also want to allow for certain type errors. If someone does not know the correct email address, I consider it convenient to give some support. So I set up aliases in /etc/aliases like:
first.last@my.domain user
f.last@my.domain user
first_last@my.domain user
flast@my.domain user
This usually provides a reasonable catch for misspelled email addresses. The same procedure applies to mail aliases for the virtual domaines. However the translation table goes into /etc/postfix/virtual.

I used domain masquerading to conceal mail sent from client computers. They are sent with my main domain:
masquerade_domains = my.domain
Did I already mention I am aware about security? Well, I am. I adjusted which client is allowed to connect:
smptd_client_restriction = permit_mynetworks, reject_unknown_client, permit

smtpd_helo_restrictions = permit_mynetworks, reject_unknown_client, reject_invalid_hostname, reject_unknown_hostname, permit_naked_ip_address, reject_non_fqdn_hostname, permit

smtpd_sender_restrictions = permit_mynetworks, reject_unknown_client, reject_invalid_hostname, reject_unknown_hostname, permit_naked_ip_address, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, permit

smtpd_recipient_restrictions = permit_mynetworks, reject_unknown_client, reject_invalid_hostname, reject_unknown_hostname, permit_naked_ip_address, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unknown_recipient_domain, permit
These restrictions are set in order of Postfix processing. I kept all restrictions in each line in order to catch Windows client behaviour.

Finally, in order to allow dovecot to connect and manipulate my folder structure without limitations, I had to set the mailbox directory:
home_mailbox = Maildir/
I experimented here and it did work. But it never was right. Some mistakes were:

home_mailbox = ~/Maildir/ ... created a directory ~/~/Maildir/ that is hard to cd into.
home_mailbox = /home/%u/Maildir/ ... created a %u directory in /home. As all mailboxes are stored into this directory, this leads to collisions. Not so good.

I am happy with the current setting. A symlink from /var/mail/user to /home/user allows for easy administration.

Finally postfix works as intended, domains are separated correctly, users can store folders in their INBOX and dovecot connects beautifully ;-)

1 comment:

Anonymous said...

Genial brief and this mail helped me alot in my college assignement. Thanks you on your information.