Debian Codegraph @

README

raw
1 ---------
2 ESMTP MTA
3 ---------
4 José Fonseca
5 ---
6 October 2008
7
8
9 Introduction
10 ~~~~~~~~~~~~
11
12 <<esmtp>> is a user configurable relay-only Mail Transfer Agent (MTA) with a
13 <<sendmail>> compatible syntax. It's based on <<libESMTP>> supporting the
14 AUTH (including the CRAM-MD5 and NTLM SASL mechanisms) and the StartTLS SMTP
15 extensions.
16
17 See the {{{http://esmtp.sourceforge.net/}ESMTP MTA home page}} for updated
18 information.
19
20
21 Configuration
22 ~~~~~~~~~~~~~
23
24
25 * Sample configuration files
26 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
28 This is a simple configuration file for a quick start:
29
30 --------------------------------------
31 hostname = mail.myisp.com:25
32 username = "myself"
33 password = "secret"
34 starttls = enabled
35
36 mda "/usr/bin/procmail -d %T"
37 --------------------------------------
38
39 If you have more than one SMTP account you have them automatically chosen for
40 you:
41
42 --------------------------------------
43 identity [email protected]
44 hostname mail.myisp.com:25
45 username "myself"
46 password "secret"
47 starttls enabled
48 default
49
50 identity [email protected]
51 hostname smtp.anotherisp.com:25
52 username "myself"
53 password "secret"
54
55 mda "/usr/bin/procmail -d %T"
56 --------------------------------------
57
58
59 * Configuration options
60 ~~~~~~~~~~~~~~~~~~~~~~~
61
62 See the <<esmtprc>> man page for more detailed information on the
63 configuration options.
64
65
66 Invocation
67 ~~~~~~~~~~
68
69 <<esmtp>> is command line compatible with <<sendmail>>.
70
71 See the <<esmtp>> man page for information on how to invoke it.
72
73
74 Interfacing to Mail User Agents
75 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76
77 Most Mail User Agents (MUAs) will work without need to configuration provided
78 that you install a symbolic from <<</usr/sbin/sendmail>>> to the esmtp
79 executable. This should already be taken care of by the <install> target of
80 the makefile when building from source.
81
82 If by any reason it is not possible to have (such as no administrator
83 privileges or the use of another MTA for local delivery) then you will have
84 to reconfigure your MUA to use the esmtp executable instead.
85
86
87 * Mutt
88 ~~~~~~
89
90 If not using a symbolic link to the esmtp executable you can make <<Mutt>> use
91 <<esmtp>> by adding the following line to your <<<~/.muttrc>>>:
92
93 -----------------------------
94 set sendmail="/path/to/esmtp"
95 -----------------------------
96
97 <<Esmtp>> supports <<sendmail>> envelope sender <-f> flag, and you are
98 advised to always enable it by adding the following line to <<Mutt>>
99 configuration file:
100
101 ---------------------
102 set use_envelope_from=yes
103 ---------------------
104
105 For debugging purposes you may prefer to put in your <<<~/.muttrc>>>:
106
107 --------------------------------------------------
108 set sendmail="/path/to/esmtp -v -X /tmp/esmtp.log"
109 --------------------------------------------------
110
111 This will enable verbose output and logging of the traffic with the SMTP
112 server.
113
114
115 Interfacing to Mail Delivery Agents
116 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117
118 <<esmtp>> relies upon a Mail Delivery Agent (MDA) for local mail delivery, so
119 you need one if you want to avoid having another MTA for local delivery.
120
121 Notice that at the moment <<esmtp>> does not honor mail aliases or
122 <<<.forward>>> files.
123
124 To deliver to other users beside yourself, the MDA must be installed with
125 <setuid> flag -- which is done by default in most Linux distributions.
126
127
128 * Procmail
129 ~~~~~~~~~~
130
131 To use <<procmail>> with <<esmtp>> set the <<<mda>>> configuration value to:
132
133 -----------------------------
134 mda="/usr/bin/procmail -d %T"
135 -----------------------------
136
137 If the mail message doesn't have a Date: header, such as those generated by
138 vixie-cron, neither <<esmtp>> or <<procmail>> will add one for you. A simple
139 hack is to pipe the message through the <<formail>> program (also part of the
140 <<procmail>> distribution), such as:
141
142 ------------------------------------------------------------
143 mda='/usr/bin/formail -a "Date: `date -R`" | /usr/bin/procmail -d %T'
144 ------------------------------------------------------------
145
146 Or, alternatively, add the following rule to your <<<.procmailrc>>>:
147
148 ----------------------------------------------
149 :0fw
150 * ! ^Date:
151 | formail -a "Date: `date -R`"
152 ------------------------------
153
154
155 Interfacing with other mail applications
156 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157
158
159 * Fetchmail
160 ~~~~~~~~~~~
161
162 By default <<fetchmail>> delivers messages via SMTP to port 25 on the machine
163 it is running. Because <<esmtp>> has no SMTP server if you are not using another
164 MTA for local delivery then you will need to configure <<fetchmail>> to use
165 <<esmtp>> executable. This is accomplished by adding the following lines to the top
166 of your <<<~/.fetchmailrc>>>:
167
168 -------------------------------------
169 defaults
170 mda "/path/to/esmtp -f %F %T"
171 -------------------------------------
172
173 Since <<esmtp>> simply forwards the mail to another MDA you can avoid this
174 redundant step by simply replacing the value inside the quotes above by
175 whichever value you use on your <<<~/.esmtprc>>>.
176
177
178 Interfacing with particular mail servers
179 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
181
182 * Gmail
183 ~~~~~~~
184
185 First edit your ~/.esmtprc according to
186 {{http://mail.google.com/support/bin/answer.py?answer=13287}}. It should look
187 like this:
188
189 -------------------------------------
190 identity [email protected]
191 hostname smtp.gmail.com:587
192 username "[email protected]"
193 password "password"
194 starttls required
195 -------------------------------------
196
197 Since Gmail requires the use of the StartTLS extension, you'll need to add
198 the Cert-Authority (CA) root certificate which signed Gmail server certificate.
199
200 Gmail's server certificated is signed by Thawte. You can either follow the
201 instructions to use Mozilla's CA cert bundle, found elsewhere in this
202 document, or download directly the
203 {{{http://www.thawte.com/roots/index.html}Thawte Premium Server CA
204 certificate}}, as shown below:
205
206 ---------------------------------------
207 mkdir ~/.authenticate
208 chmod 0700 ~/.authenticate
209 wget https://www.verisign.com/support/thawte-roots.zip
210 unzip -p thawte-roots.zip 'Thawte Server Roots/ThawtePremiumServerCA_b64.txt' > ~/.authenticate/ca.pem
211 chmod 0600 ~/.authenticate/ca.pem
212 ---------------------------------------
213
214
215 Using the StartTLS extension
216 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
218 TLS support in <<libESMTP>> although usable is not yet as robust and
219 featureful as the rest of the library. At the moment to use the StartTLS
220 extension you will need to:
221
222 [[1]] create a <<<~/.authenticate>>> directory for the certificates. All files
223 and directories in <<<~/.authenticate>>> (including itself) must be user-readable
224 only, i.e., they must have 0600 and 0700 permissions respectively.
225
226 [[2]] put the certificate of the trusted Cert-Authority that signed the
227 server certificate into <<<~/.authenticate/ca.pem>>>.
228
229 [[3]] if a client certificate is required by the server then put it
230 (including the private key) into
231 <<<~/.authenticate/private/smtp-starttls.pem>>> or
232 <<<~/.authenticate/host.name/private/smtp-starttls.pem>>>. If your client
233 certificate has a passphrase then it should be specificied with the
234 <certificate_passphrase> configuration.
235
236 [[4]] enable (or require) the StartTLS extension with the <starttls>
237 configuration option. Note that the value of the <hostname> configuration
238 option of the server you connect MUST match the name in the server
239 certificate, since it will be used to verify the server identity.
240
241 In case of failure no error message will appear. Instead, <<libESMTP>> will
242 terminate the SMTP connection right after issuing the STARTLS command.
243
244 For more information about TLS support in <<libEMSTP>> see the comments in
245 <<<smtp-tls.c>>> in the <<libESMTP>> source distribution.
246
247
248 * Using CA root certificates from mozilla.org
249 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250
251 Mozilla.org's browsers already ship with a bundle of CA root certificates. For most cases
252 this bundle should suffice. You can download the bundle a format suitable to esmtp from
253 {{http://curl.haxx.se/docs/caextract.html}}, as
254
255 ---------------------------------------
256 mkdir ~/.authenticate
257 chmod 0700 ~/.authenticate
258 wget http://curl.haxx.se/ca/cacert.pem
259 mv cacert.pem ~/.authenticate/ca.pem
260 chmod 0600 ~/.authenticate/ca.pem
261 ---------------------------------------
262
263
264
265 * Using CA root certificates from debian
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
268 If you use Debian, you can also use the CA root certificates included in the
269 <ca-certificates> package:
270
271 ---------------------------------------
272 mkdir ~/.authenticate
273 chmod 0700 ~/.authenticate
274 sudo apt-get install ca-certificates
275 cp -a /etc/ssl/certs/ ~/.authenticate/ca
276 chmod -R go-rwx ~/.authenticate/ca
277 ---------------------------------------
278
279
280 * Determining the Cert-Authority certificate
281 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282
283 It may happen that the mail server certificate is signed by an unknown or
284 custom root certificate. If you think that may be your case you can try to
285 figure out which one is using <<openssl>>:
286
287 -------------
288 openssl s_client -connect hostname:port
289 --------------
290
291 Depending on the SMTP mail server, you might need to play with the port number
292 or add '-starttls smtp' option.
293
294 Look for lines in the output which can provide clues for the certification
295 authority such as:
296
297 ---------------
298 issuer=/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Premium Server CA/[email protected]
299 ---------------
300
301 Once you are in possession of the root certificate, you can check if it
302 validates the server certificate by passing it on the <<<-CAfile>>> option. It is
303 does then you'll get a line like:
304
305 --------
306 Verify return code: 0 (ok)
307 --------
308
309 See also {{http://curl.haxx.se/docs/sslcerts.html}}
310
311
312 Queueing support for dial-in users
313 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314
315 To enable mail queueing support for esmtp, a wrapper script has been included
316 with this distribution. It's goal is to be called instead of esmtp when a mail
317 client requests sending of an email, and then periodically or on request to
318 actually send pending emails.
319 First choose a place to save the script. This path will be referenced by <<DIR>>
320 in the following examples. Then you need to create symbolic links to it with
321 special names at one of the directories in your $PATH environment variable, e.g.
322 $HOME/bin:
323
324 ---------------
325 cd $HOME/bin
326 ln -s <<DIR>>/esmtp-wrapper sendmail
327 ln -s <<DIR>>/esmtp-wrapper deliver
328 ln -s <<DIR>>/esmtp-wrapper mailq
329 ---------------
330
331 When esmtp-wrapper is called either as sendmail or esmtp, it will first enqueue the
332 mail by saving the mail itself and the given parameters (like, e.g. the envelope-from
333 address) into a directory within the caller's $HOME/.esmtp_queue directory, and then
334 try to directly deliver the queue in background.
335 In difference to enqueueing, successful delivery is not treated as critical at this
336 point and therefore won't disturb the mail client's workflow.
337 To trigger delivery of all enqueued mails, execute esmtp-wrapper either as deliver,
338 or as mailq using '-q' as first parameter.
339 You can check whether there are enqueued mails either by simply issueing <<mailq>> or
340 manually checking your $HOME/.esmtp_queue directory.
341 Maybe the best way to trigger mail delivery is within some script which is called after
342 the internet connection has been enabled. Alternatively I find the following crontab entry
343 quite useful:
344
345 ---------------
346 */10 * * * * /bin/ping -c1 mail.example.com >/dev/null 2>&1 && $HOME/bin/deliver
347 ---------------
348
349 it will check every 10 minutes whether the mailserver mail.example.com is reachable and
350 on success deliver all mails in the queue.
351 BEWARE: always make sure the script is called by the right user, as esmtp-wrapper depends
352 on that.