Changes between Version 15 and Version 16 of howto/SetupPostfix
- Timestamp:
- Jun 18, 2011, 1:02:47 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
howto/SetupPostfix
v15 v16 10 10 This How-to is part of the [wiki:howto/SetupFetchmail Fetchmail] -> [wiki:howto/SetupPostfix Postfix] -> [wiki:howto/SetupDovecot Dovecot] advanced e-Mail set-up. 11 11 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]. 13 13 14 14 Distribution 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]. … … 28 28 === Postfix === 29 29 30 Install postfix with:30 We'll want everything, so use the following script to get it: 31 31 32 32 {{{ 33 port install postfix +tls +ldap 33 #!/macports/bin/bash 34 35 declare -a toInstall 36 toInstall=( \ 37 postfix+dovecot_sasl+tls+pcre+mysql5+postgresql90 postgrey \ 38 dovecot2+ldap+mysql5+postgresql90 dovecot2-sieve \ 39 fetchmail \ 40 squirrelmail \ 41 ) 42 43 for doInstall in ${toInstall[@]} 44 do 45 (sudo port install ${doInstall//+/ +}) ; wait 46 done 47 48 exit 34 49 }}} 35 36 or - alternatively - use the postfix which comes pre installed with Max OSX.37 50 38 51 == Configuration == 39 52 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). 53 The 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 60 Don't mess with this file at all at this point in the process !!! 41 61 42 62 === Step 1: '''setup main.cf''' === 43 63 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: 64 You'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: 49 65 50 66 {{{ 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 67 grep ' =' /macports/etc/postfix/main.cf.default 55 68 }}} 56 69 57 Note: if you don't use an domain name apart from {{{.local}}} then you can remove the duplicate. 70 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 ! 58 71 59 ==== se t relayhost====72 ==== sending email ==== 60 73 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.74 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. 62 75 63 The following lines need attention:76 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. 64 77 65 78 {{{ 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 86 myhostname = 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 95 mydomain = 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 104 myorigin = $mydomain 67 105 }}} 68 106 69 ==== /usr <-> /opt/local ==== 107 Setting '''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 117 inet_interfaces = localhost 118 }}} 70 119 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}}}. 120 This blocks other computers from relaying email through your computer 121 {{{ 122 #mynetworks_style = class 123 #mynetworks_style = subnet 124 #mynetworks_style = host 125 mynetworks_style = host 126 }}} 73 127 74 ==== /private <-> /opt/local ==== 128 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. 129 {{{ 130 #relayhost = $mydomain 131 #relayhost = [gateway.my.domain] 132 #relayhost = [mailserver.isp.tld] 133 #relayhost = uucphost 134 #relayhost = [an.ip.add.ress] 135 relayhost = [smtp.isp-name.com] 136 }}} 75 137 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}}}.78 138 79 === = verify your changes ====139 === Step 2: '''setup of aliases''' === 80 140 81 Use "diff" to list the differences between the original (main.cf.sample) and the current main.cf file. 141 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 : 142 {{{ 143 Jun 17 23:03:52 Pro17 postfix/master[262]: warning: /macports/libexec/postfix/smtpd: bad command startup -- throttling 144 Jun 17 23:04:52 Pro17 postfix/smtpd[17162]: fatal: open database /macports/etc/postfix/aliases.db: No such file or directory 145 Jun 17 23:04:53 Pro17 postfix/master[262]: warning: process /macports/libexec/postfix/smtpd pid 17162 exit status 1 146 }}} 82 147 83 Note that "main.cf.default" lists all possible parameters and their defaults for the "cf" file. 148 These 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 }}} 84 159 85 === Step 2: '''setup relay passwords''' === 160 At present, we'll simply go with the default values 161 {{{ 162 alias_database = hash:/macports/etc/postfix/aliases 163 alias_maps = hash:/macports/etc/postfix/aliases 164 }}} 165 and not change anything at all in main.cf 86 166 87 TODO 167 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: 168 169 {{{ 170 # Person who should get root's mail. Don't receive mail as root! 171 #root: you 172 }}} 173 174 Un-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 177 Then, just issue this command : {{{newaliases}}} and aliases.db will be created for you. 88 178 89 179 === Step 3: '''starting the daemon''' ===