2 # Copyright (C) 2016 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 # /usr/share/doc/exim4-base/README.Debian.gz
20 # /usr/share/doc/exim4-base/spec.txt.gz
22 # routers, transports, and authenticators are sections, and you define
23 # driver instances in those sections, and the manual calls them driver
24 # types but there is also a more specific "type" of driver, which is specified
25 # with the driver = some_module setting in the driver.
27 # the driver option must precede and private options (options that are
28 # specific to that driver), so follow example of putting it at beginning.
30 # The full list of option settings for any particular driver instance,
31 # including all the defaulted values, can be extracted by making use of
32 # the -bP command line option.
34 # exim clear out message queue. as root:
35 # adapted from somewhere on stackoverflow.
36 # ser stop exim4; sleep 1; exim -bp | exiqgrep -i | xargs exim -Mrm; ser start exim4
38 # fastmail has changed their smtp server, but the old one still works,
39 # I see no reason to bother changing.
40 # New one is smtp.fastmail.com
42 # test delivery & rewrite settings:
43 #exim4 -bt ian@localhost
47 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
50 postfix
() { [[ $type == postfix
]]; }
51 exim
() { [[ $type == exim4
]]; }
52 if ! exim
&& ! postfix
; then
53 echo "$1: error: expected exim4 or postfix as first arg"
58 host=mail.messagingengine.com
59 forward
=$HOSTNAME@
$PERSONAL_DOMAIN
61 # ses initially suggests port 25, but I had problems connecting to that.
62 host=email-smtp.us-west-2.amazonaws.com
63 forward
=$HOSTNAME@
$IMPERSONAL_DOMAIN
66 relayhost
="[$host]:587" # postfix
67 smarthost
="$host::587" # exim
69 # background: This also works instead of ~/.forward
70 # s sed -i --follow-symlinks '/^root/d' /etc/aliases ||:
71 #echo "root: $HOSTNAME@$SOME_DOMAIN" | s tee -a /etc/aliases
72 # this can't be a symlink and has permission restrictions
73 # it might work in /etc/aliases, but this seems more proper.
74 e
$forward > ~
/.forward
75 e
$forward | s
tee /root
/.forward
77 # linode image has a root alias. completely useless, remove it.
78 sudo
sed -i '/^root:/d' /etc
/aliases
83 # offlineimap uses this too, it is much easier to use one location than to
84 # condition it's config and postfix's config
86 fedora
) s lnf
-T ca-certificates.crt
/etc
/ssl
/ca-bundle.trust.crt
;;
90 read -r domain pass
< <(s
cat /etc
/mailpass
)
92 # dunno why, but debian installed postfix with builddep emacs
93 # but I will just explicitly install it here since
94 # I use it for sending mail in emacs.
96 s debconf-set-selections
<<EOF
97 postfix postfix/main_mailer_type select Satellite system
98 postfix postfix/mailname string $HOSTNAME
99 postfix postfix/relayhost string $relayhost
105 # Settings from reading the output when installing on debian,
106 # then seeing which were different in a default install on arch.
107 # I assume the same works for fedora.
109 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
110 mailbox_size_limit = 0
111 relayhost = $relayhost
112 inet_interfaces = loopback-only
115 s systemctl
enable postfix
116 s systemctl start postfix
118 # i'm assuming mail just won't work on systems without the sasl_passwd.
120 smtp_sasl_auth_enable = yes
121 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
122 smtp_sasl_security_options = noanonymous
123 smtp_tls_security_level = secure
124 message_size_limit = 20480000
125 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
126 inet_protocols = ipv4
128 # msg_size_limit: I ran into a log file not sending cuz of size. double from 10 to 20 meg limit
129 # inet_protocols: without this, postfix tries an ipv6 lookup then gives
130 # up and fails. snippet from syslog: type=AAAA: Host not found, try again
133 # mailpass is just a name i made up, since postfix and
134 # exim both use a slightly crazy format to translate to
135 # each other, it's easier to use my own format.
136 f
=/etc
/postfix
/sasl_passwd
139 echo "[$domain]:587 ${pass/@/#}" | s
dd of
=/etc
/postfix
/sasl_passwd
>/dev
/null
140 s postmap
hash:/etc
/postfix
/sasl_passwd
141 s service postfix reload
144 # wording of question from dpkg-reconfigure exim4-config
145 # 1. internet site; mail is sent and received directly using SMTP
146 # 2. mail sent by smarthost; received via SMTP or fetchmail
147 # 3. mail sent by smarthost; no local mail
148 # 4. local delivery only; not on a network
149 # 5. no configuration at this time
151 # default mailname is $HOSTNAME.lan,
152 # mailname makes addresses like "root" be root@mailname
153 # and a qualified domain does not get forwarded per
154 # .forward. whatever, this fixes that.
155 s debconf-set-selections
<<EOF
156 exim4-config exim4/dc_eximconfig_configtype select mail sent by smarthost; no local mail
157 exim4-config exim4/dc_smarthost string $smarthost
158 exim4-config exim4/use_split_config boolean true
159 exim4-config exim4/mailname string $HOSTNAME
161 # light version does not have sasl auth support.
162 pi exim4-daemon-heavy
164 f
=/etc
/exim
4/passwd.client
166 s
chmod 600 $f # make it 600 before writing sensitive info
167 echo "$domain:${pass/:/::}" | s
dd of
=$f >/dev
/null
168 # https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
169 # i only need .forwards, so just doing that one.
170 cd /etc
/exim
4/conf.d
/router
172 b
=${a}_higher_priority
175 # sed to make the router name unique
176 sed -r s
/^
\\S
+:/$b:/ 600_exim4-config_
$a >$tmp
177 if diff -q >/dev
/null
$tmp $of; then
178 s
dd if=$tmp of
=$of >/dev
/null
183 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
185 sdir
=/var
/spool
/$type
186 if [[ $
(readlink
-f $sdir) != $dir ]]; then
188 if [[ ! -e $dir && -d $sdir ]]; then
197 # if I wanted the from address to be renamed and sent to a different address,
198 # echo "sdx@localhost development@localhost" | sudo dd of=/etc/postfix/recipient_canonical
199 # sudo postmap hash:/etc/postfix/recipient_canonical
200 # sudo service postfix reload