wiki:howto/SetupPostfix

Version 18 (modified by BjarneDMat, 13 years ago) (diff)

--

<- Back to the HOWTO section

How to set-up Postfix

  • Audience: Advanced E-Mail set-up
  • Requires: MacPorts >= 1.6, mail/postfix, shells/zsh-devel

Introduction

This How-to is part of the Fetchmail -> Postfix -> Dovecot advanced e-Mail set-up.

Postfix is a mail transfer agent which can distribute your in- and out-bound mail. The set-up described here will distribute inbound mail to a Dovecot IMAP server and outbound mail to an internet service provider.

Distribution of E-Mail directly to the end receiver is one of the joys of the internet which has been destroyed by SPAM.

Installation

First set-up a mail storage where postfix will store your mail. See Dovecot for a possible set-up. Without a proper mail storage you might have difficulty accessing your mail later.

Z-Shell

Install Z-Shell if you are planning to use the attached command files:

sudo port install zsh-devel

Postfix

We'll want everything, so use the following script to get it:

#!/opt/local/bin/bash

declare -a toInstall
toInstall=( \
            postfix+dovecot_sasl+tls+pcre+mysql5 postfixadmin
            sqlgrey sgwi \
            dovecot2+ldap+mysql5 dovecot2-sieve \
            fetchmail \
            roundcubemail \
         )

for doInstall in ${toInstall[@]}
do
    (sudo port install ${doInstall//+/ +}) ; wait
done

exit

Configuration

The configuration is done several files of which we'll need at least three:

  1. master.cf
  2. main.cf
  3. alias

Step 0: master.cf

Don't mess with this file at all at this point in the process !!!

Step 1: setup main.cf

You'll find all the default settings in /opt/local/etc/postfix/main.cf.default - all of these settings are explained in some depth here postconf.5 or man 5 postconf. You'll find a sample primary configuration in /opt/local/etc/postfix/main.cf.sample. main.cf.sample is extensively commented, but to get an overview of the which setting are present in the file execute this command:

grep ' =' /opt/local/etc/postfix/main.cf.default

We'll change some of them in the following, but a lot of them has to be left alone and are not to be messed with under most circumstances as you'll completely mess up your configuration if you do so - you have been duly warned !

sending email

Let's start by getting postfix to send email from the local computer. I'm assuming that you'll be running a webserver that'll need to send and receive eg confirmation email as well as receiving the general email for one or more domains.

The hostname command will give you an a value for what your computer is called, but this is in many cases not a useful name. If you get your IP-number or DNS-settings from a DHCP-server the rDNS-name will be your hostname eg 4604ds1-ynoe.2.fullrate.dk and that's not what you in most cases want your recipients to see as the sending computer. Furthermore, hostname only reflects what the first interface as listed in the Network Preferences Pane is called.

# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname  = computer.example.com

# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
#mydomain = domain.tld
mydomain  = example.com

# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
#
#myorigin = $myhostname
#myorigin = $mydomain
#myorigin = $myhostname
#myorigin = $mydomain
myorigin  = $mydomain

Setting inet_interfaces to localhost effectively blocks receipt of email. We'll change this setting when we look at receiving email.

# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.  By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces  = localhost

This blocks other computers from relaying email through your computer

#mynetworks_style = class
#mynetworks_style = subnet
#mynetworks_style = host
mynetworks_style  = host

Your outbound mail might need to go through a relayhost as most of us can't send e-mail directly anymore. Due to spam from bot-nets many ISPs block port 25 in their firewall. Mostly it'll be smtp.ISP-name.tld or something like that, but you ought to be able to find it on the ISPs website. This is also the setting you use in Mail.app for sending email.

#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
relayhost  = [smtp.isp-name.com]

Step 2: setup of aliases

We'll need at least one entry in the aliases database. If aliases.db isn't present, the postfix master will start, but upon the first activity you'll get repeated lines of this kind :

Jun 17 23:03:52 Pro17 postfix/master[262]: warning: /opt/local/libexec/postfix/smtpd: bad command startup -- throttling
Jun 17 23:04:52 Pro17 postfix/smtpd[17162]: fatal: open database /opt/local/etc/postfix/aliases.db: No such file or directory
Jun 17 23:04:53 Pro17 postfix/master[262]: warning: process /opt/local/libexec/postfix/smtpd pid 17162 exit status 1

These are lines in main.cf of interest:

#alias_maps = dbm:/etc/aliases
#alias_maps = hash:/etc/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
#alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases

At present, we'll simply go with the default values

alias_database = hash:/opt/local/etc/postfix/aliases
alias_maps = hash:/opt/local/etc/postfix/aliases

and not change anything at all in main.cf

aliases.db is created on the basis of the flat file aliases. Actually, we'll only need to edit one single line in aliases in order to get things working:

# Person who should get root's mail. Don't receive mail as root!
#root:		you

Un-comment the line starting with #root and change you to one of the following two options

  1. an ordinary email address: "person@…"
  2. the short name of a local user

Then, just issue this command : newaliases and aliases.db will be created for you.

Step 3: starting the daemon

Restart_Postfix.command This command creates or updates the database files. Run via "sudo."

Step 4: testing the deamon

The attached Test_Postfix.command will send a test e-mail to your self - provided you replaced my_name and my_computer with your own name and computer name.

Optional Parts

TODO: What else can be done?

<- Back to the HOWTO section

Attachments (3)

Download all attachments as: .zip