Postfix
From Gentoo Linux Wiki
Postfix is a free open source mail transfer agent (MTA), a computer program for the routing and delivery of email. It is intended as a fast, easy-to-administer, and secure alternative to the widely-used Sendmail MTA.
Contents |
[edit] Install
To install postfixadmin simply execute: emerge -av postfixadmin
[edit] Configure
Postfix will allow us to handle users with ease throughout this setup. Once postfixadmin is installed you can easily add aliases and mailboxes! So Let's start!
It should be noted that Postfix does not like a comment on the same line as a variable.
Here is an example of a bad comment:
| Code: Misc |
myhostname = host.domain.tld # my fqdn |
Here is an example of a good comment
| Code: Misc |
# my fqdn myhostname = host.domain.tld |
Postfix needs to be tested with a basic config to make sure all parts are working before moving on to the more complicate virtual setup. This will often save hours of troubleshooting later.
| File: /etc/postfix/main.cf |
myhostname = host.domain.tld mydomain = domain.tld inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, $mydomain mynetworks = 192.168.1.0/24, 127.0.0.0/8 |
We need to turn on debugging, so if something doesn't work you can troubleshoot. So, open up /etc/postfix/master.cf and add a '-vv' to the end of virtual, local, smtp, and smtpd services.
| File: /etc/postfix/master.cf |
smtp inet n - n - - smtpd -vv |
The next step is configure you /etc/mail/aliases file. All that needs to be done if to add a entry for the root user. thing we need to do is get or base aliases going. Here is a list of standard RFC 2142 aliases and common aliases (these are taken directly from my /etc/mail/aliases, incase you don't have them). Place them in /etc/mail/aliases:
| Code: /etc/mail/aliases |
# Well-known aliases -- these should be filled in! root: localuser |
We now need to update our aliases database, so run the following:
| Code: Commands |
# /usr/bin/newaliases |
Postfix should work now, so let's get it going:
| Code: Commands |
# /etc/init.d/postfix start |
And since we want it to start by default, we need to add it to the default startup:
| Code: Commands |
# rc-update add postfix default |
It's *highly* recommended you test your Postfix installation right now, so do that we shall (colors that are highlightes in red are commands you need to type; colors that are in black are the responses you should get):
telnet 127.0.0.1 25 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 220 mail.domain.tld ESMTP Postfix helo mail.domain.tld 250 mail.domain.tld mail from:<a@a.com> 250 Ok rcpt to:<root@domain.tld> 250 Ok data 354 End data with <CR><LF>.<CR><LF> To: you@domain.tld Subject: Test Email <enter> Cows go moo. . 250 Ok: queued as CC89074009 quit 221 Bye Connection closed by foreign host.
Your queued number should be different than listed above. If you recieve any problems, you should troubleshoot them before proceeding any further.
[edit] Virtual setup
Create the mailbox locations with the correct privilidges:
mkdir /var/spool/postfix/virtual
chown postfix:postfix /var/spool/postfix/virtual
chmod a+rwx /var/spool/postfix/virtual
i don't think, this is a good idea, don't we have a user vmail, that does deal with the virtual directories?
The following are sample postfix configuration files. Note that you will need to change the user (UID) and group (GID) ID's to match those found on your system (in /etc/passwd and /etc/group respectively).
| File: /etc/postfix/main.cf |
alias_database = hash:/etc/postfix/aliases alias_maps = $alias_database myhostname = <yourhostname> mydomain = <your_domain> myorigin = $myhostname mydestination = $myhostname, localhost.$mydomain mail_spool_directory = /var/spool/mail home_mailbox = Mailbox debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb = $daemon_directory/$process_name $process_id & sleep 5 disable_vrfy_command = yes show_user_unknown_table_name = no virtual_transport = virtual virtual_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf virtual_minimum_uid = 207 # REMEBER THIS MUST BE CHANGED TO YOUR UID FOR "postfix" FROM /etc/passwd virtual_uid_maps = static:207 # REMEBER THIS MUST BE CHANGED TO YOUR UID FOR "postfix" FROM /etc/passwd virtual_gid_maps = static:207 # REMEBER THIS MUST BE CHANGED TO YOUR UID FOR "postfix" FROM /etc/passwd virtual_mailbox_base = /var/spool/postfix/virtual virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_limit = 51200000 # Additional for quota support virtual_create_maildirsize = yes virtual_mailbox_extended = yes virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf virtual_mailbox_limit_override = yes virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later. virtual_overquota_bounce = yes |
| File: /etc/postfix/mysql_virtual_alias_maps.cf |
user = postfix password = postfix hosts = localhost dbname = postfix table = alias select_field = goto where_field = address |
| File: /etc/postfix/mysql_virtual_domains_maps.cf |
user = postfix password = postfix hosts = localhost dbname = postfix table = domain select_field = description where_field = domain #additional_conditions = and backupmx = '0' and active = '1' |
| File: /etc/postfix/mysql_virtual_mailbox_maps.cf |
user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = maildir where_field = username #additional_conditions = and active = '1' |
| File: /etc/postfix/mysql_relay_domains_maps.cf |
user = postfix password = postfix hosts = localhost dbname = postfix table = domain select_field = domain where_field = domain additional_conditions = and backupmx = '1' |
| File: /etc/postfix/mysql_virtual_mailbox_limit_maps.cf |
user = postfix password = showmethemail hosts = localhost dbname = postfix table = mailbox select_field = maildir where_field = quota #additional_conditions = and active = '1' |
And now we restart postfix: /etc/init.d/postfix restart
[edit] Postfix Admin
To begin setting up PostfixAdmin, open a browser, go to http://localhost/postfixadmin and start the setup process by clicking on the "setup" link. Once the setup process has completed, you'll need to delete the setup script: rm /var/www/localhost/htdocs/postfixadmin/setup.php
Open up the postfix admin config file (/var/www/localhost/htdocs/postfixadmin/config.inc.php by default) and change the following settings:
- "change-this-to-your-domain.tld" to your domain.
- config_path to YES
- domain_in_mailbox to NO
- 'encrypt' to 'cleartext'
You will also need to change your postfix user/pass from the usual admin:admin to something more secure. To do this run: htpasswd2 /var/www/localhost/htdocs/postfixadmin/admin/.htpasswd admin (You may also want to consider changing the username)
To keep local users from reading your postfixadmin directory, execute the following to change its permissions:
chown -R apache:apache /var/www/localhost/htdocs/postfixadmin/
chmod -R 700 /var/www/localhost/htdocs/postfixadmin/
