Changes between Version 15 and Version 16 of howto/SetupPostfix


Ignore:
Timestamp:
Jun 18, 2011, 1:02:47 AM (13 years ago)
Author:
BjarneDMat
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • howto/SetupPostfix

    v15 v16  
    1010This How-to is part of the [wiki:howto/SetupFetchmail Fetchmail] ->  [wiki:howto/SetupPostfix Postfix] -> [wiki:howto/SetupDovecot Dovecot] advanced e-Mail set-up.
    1111
    12 [wikipedia:Postfix_%28software%29 Postfix] is a [wikipedia:Mail_transfer_agent mail transfer agent] which can distribute your in and outbound mail. The set-up described here will distribute inbound mail to a [wikipedia:Dovecot_%28software%29 Dovecot]  [wikipedia:Internet_Message_Access_Protocol IMAP] server and outbound mail to an [wikipedia:Internet_service_provider internet service provider].
     12[wikipedia:Postfix_%28software%29 Postfix] is a [wikipedia:Mail_transfer_agent mail transfer agent] which can distribute your in- and out-bound mail. The set-up described here will distribute inbound mail to a [wikipedia:Dovecot_%28software%29 Dovecot]  [wikipedia:Internet_Message_Access_Protocol IMAP] server and outbound mail to an [wikipedia:Internet_service_provider internet service provider].
    1313
    1414Distribution of E-Mail directly to the end receiver is one of the joys of the internet which has been destroyed by [wikipedia:E-mail_spam SPAM].
     
    2828=== Postfix ===
    2929
    30 Install postfix with:
     30We'll want everything, so use the following script to get it:
    3131
    3232{{{
    33 port install postfix +tls +ldap
     33#!/macports/bin/bash
     34
     35declare -a toInstall
     36toInstall=( \
     37            postfix+dovecot_sasl+tls+pcre+mysql5+postgresql90 postgrey \
     38            dovecot2+ldap+mysql5+postgresql90 dovecot2-sieve \
     39            fetchmail \
     40            squirrelmail \
     41         )
     42
     43for doInstall in ${toInstall[@]}
     44do
     45    (sudo port install ${doInstall//+/ +}) ; wait
     46done
     47
     48exit
    3449}}}
    35 
    36 or - alternatively - use the postfix which comes pre installed with Max OSX.
    3750
    3851== Configuration ==
    3952
    40 Most of the postfix configuration is done in the [attachment:main.cf] file which you find either in {{{/opt/local/etc/postfix}}} (macports) or {{{/etc/postfix}}} (OSX).
     53The configuration is done several files of which we'll need at least three:
     54 1. master.cf
     55 1. main.cf
     56 1. alias
     57
     58=== Step 0: '''master.cf''' ===
     59
     60Don't mess with this file at all at this point in the process !!!
    4161
    4262=== Step 1: '''setup main.cf''' ===
    4363
    44 ==== set hostname and domain ====
    45 
    46 Search for {{{my_computer}}} and {{{my_domain}}} in {{{main.cf}}} and replace them with the domain name and computer name of your computer. You can find them out with the {{{hostname}}} command.
    47 
    48 The following lines need attention:
     64You'll find all the default settings in '''/macports/etc/postfix/main.cf.default''' - all of these settings are explained in some depth here [http://www.postfix.org/postconf.5.html postconf.5] or {{{man 5 postconf}}}.  You'll find a sample primary configuration in '''/macports/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:
    4965
    5066{{{
    51 myhostname = my_computer.local
    52 mydomain = my_domain.com
    53 mydestination = localhost,localhost.my_domain.com,my_computer,my_computer.local,my_computer.my_domain.com
    54 masquerade_domains = my_domain.com
     67grep ' =' /macports/etc/postfix/main.cf.default
    5568}}}
    5669
    57 Note: if you don't use an domain name apart from {{{.local}}} then you can remove the duplicate.
     70We'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 !
    5871
    59 ==== set relayhost ====
     72==== sending email ====
    6073
    61 Your outbound mail needs to go to a relayhost as most of us can't send e-mail directly any more. My relayhost is {{{smtp.my_domain.com}}} this does not need to be for you.
     74Let'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.
    6275
    63 The following lines need attention:
     76The {{{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.
    6477
    6578{{{
    66 relayhost = [smtp.my_domain.com]
     79# The myhostname parameter specifies the internet hostname of this
     80# mail system. The default is to use the fully-qualified domain name
     81# from gethostname(). $myhostname is used as a default value for many
     82# other configuration parameters.
     83#
     84#myhostname = host.domain.tld
     85#myhostname = virtual.domain.tld
     86myhostname  = computer.example.com
     87
     88# The mydomain parameter specifies the local internet domain name.
     89# The default is to use $myhostname minus the first component.
     90# $mydomain is used as a default value for many other configuration
     91# parameters.
     92#
     93#mydomain = domain.tld
     94#mydomain = domain.tld
     95mydomain  = example.com
     96
     97# The myorigin parameter specifies the domain that locally-posted
     98# mail appears to come from. The default is to append $myhostname,
     99#
     100#myorigin = $myhostname
     101#myorigin = $mydomain
     102#myorigin = $myhostname
     103#myorigin = $mydomain
     104myorigin  = $mydomain
    67105}}}
    68106
    69 ==== /usr <-> /opt/local ====
     107Setting '''inet_interfaces''' to '''localhost''' effectively blocks receipt of email. We'll change this setting when we look at receiving email.
     108{{{
     109# The inet_interfaces parameter specifies the network interface
     110# addresses that this mail system receives mail on.  By default,
     111# the software claims all active interfaces on the machine. The
     112# parameter also controls delivery of mail to user@[ip.address].
     113#
     114#inet_interfaces = all
     115#inet_interfaces = $myhostname
     116#inet_interfaces = $myhostname, localhost
     117inet_interfaces  = localhost
     118}}}
    70119
    71 Depending on which version of postfix (osx vs. macports) you use you have to change all lines containing {{{/usr}}} to {{{/opt/local}}}.
    72 The MacPorts installation automatically changes these in main.cf to {{{/opt/local}}}.
     120This blocks other computers from relaying email through your computer
     121{{{
     122#mynetworks_style = class
     123#mynetworks_style = subnet
     124#mynetworks_style = host
     125mynetworks_style  = host
     126}}}
    73127
    74 ==== /private <-> /opt/local ====
     128Your 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.
     129{{{
     130#relayhost = $mydomain
     131#relayhost = [gateway.my.domain]
     132#relayhost = [mailserver.isp.tld]
     133#relayhost = uucphost
     134#relayhost = [an.ip.add.ress]
     135relayhost  = [smtp.isp-name.com]
     136}}}
    75137
    76 Depending on which version of postfix (osx vs. macports) you use you have to change all lines containing {{{/private}}} to {{{/opt/local}}}.
    77 The MacPorts installation automatically changes these in main.cf to {{{/opt/local}}}.
    78138
    79 ==== verify your changes ====
     139=== Step 2: '''setup of aliases''' ===
    80140
    81 Use "diff" to  list the differences between the original (main.cf.sample) and the current main.cf file.
     141We'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 :
     142{{{
     143Jun 17 23:03:52 Pro17 postfix/master[262]: warning: /macports/libexec/postfix/smtpd: bad command startup -- throttling
     144Jun 17 23:04:52 Pro17 postfix/smtpd[17162]: fatal: open database /macports/etc/postfix/aliases.db: No such file or directory
     145Jun 17 23:04:53 Pro17 postfix/master[262]: warning: process /macports/libexec/postfix/smtpd pid 17162 exit status 1
     146}}}
    82147
    83 Note that "main.cf.default" lists all possible parameters and their defaults for the "cf" file.
     148These are lines in main.cf of interest:
     149{{{
     150#alias_maps = dbm:/etc/aliases
     151#alias_maps = hash:/etc/aliases
     152#alias_maps = hash:/etc/aliases, nis:mail.aliases
     153#alias_maps = netinfo:/aliases
     154#alias_database = dbm:/etc/aliases
     155#alias_database = dbm:/etc/mail/aliases
     156#alias_database = hash:/etc/aliases
     157#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
     158}}}
    84159
    85 === Step 2: '''setup relay passwords''' ===
     160At present, we'll simply go with the default values
     161{{{
     162alias_database = hash:/macports/etc/postfix/aliases
     163alias_maps = hash:/macports/etc/postfix/aliases
     164}}}
     165and not change anything at all in main.cf
    86166
    87 TODO
     167aliases.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:
     168
     169{{{
     170# Person who should get root's mail. Don't receive mail as root!
     171#root:          you
     172}}}
     173
     174Un-comment the line starting with '''#root''' and change '''you''' to one of the following two options
     175 1. an ordinary email address: "person@domain.tld"
     176 1. the short name of a local user
     177Then, just issue this command : {{{newaliases}}} and aliases.db will be created for you.
    88178
    89179=== Step 3: '''starting the daemon''' ===