posts:mutt: copy post over from Drexel Liki.
[blog.git] / posts / Mutt.mdwn
1 [[!meta  date="2009-02-04 13:06:00"]]
2
3 [Mutt][] is a simple, configurable mail user agent [MUA][]/email
4 client.  I got tired of using webmail to check my email, so I got Mutt
5 set up on my computer instead.  Mutt is intended to be an email
6 browser, so most versions don't have built in [[SMTP]] support.  For a
7 simple setup, you can use an external SMTP client like [msmtp][],
8 which is how we'll do it in the examples below.
9
10 Install
11 =======
12
13 For Debian-type distros (e.g. Debian, Ubuntu, …), you can install Mutt
14 and msmpt with
15
16   $ apt-get install mutt msmtp
17
18 Configure
19 =========
20
21 You configure Mutt with the file `~/.muttrc`.  To set it up with the
22 Drexel email system, I looked up the server addresses, and created the
23 `.muttrc` file:
24
25     # login information
26     set imap_user='<your-username>@drexel.edu'
27     set imap_pass='<your-password>'
28     set from="<your-username>@drexel.edu"
29     set use_from=yes # required so msmtp knows which account to use to send mails
30
31     # setting your realname is optional, but drexel addresses can be cryptic...
32     set realname="<your-realname>"
33
34     # email server location
35     set spoolfile=imaps://<your-username>@imap.mail.drexel.edu:993/INBOX
36     set folder=imaps://<your-username>@imap.mail.drexel.edu:993/
37
38     # use msmtp for sending mail
39     set sendmail=/usr/bin/msmtp # Debian-style system path, yours may be different
40
41     # save copies of sent email to the ${folder}Sent directory
42     # the '+' expands to $folders (like '~' to $HOME in bash)
43     set record=+Sent
44
45     set mail_check=600 # check for new mail every 10 minutes when user is active
46     set timeout=600    # check for new mail every 10 min. when user is not active
47
48     set editor="/usr/bin/emacs -nw"   # use emacs for writing emails
49     set edit_headers                  # allow editing headers while you're in emacs
50
51 Since this file contains your password, you should not allow other
52 users to read it.
53
54     $ chmod 600 ~/.muttrc
55
56 This still isn't terribly secure, so you could remove the password
57 line entirely, in which case Mutt prompts you for it when it tries to
58 log in (just like webmail does).
59
60 The `mail_check` and `timeout` settings set up how often Mutt checks
61 for new mail, which I've set to be pretty slow.  You can type `$` to
62 sync, whenever you want to send outgoing mail or check for new mail.
63
64 Googling `.muttrc` should turn up tons of other goodies, or try `man
65 muttrc`.
66
67 You also have to configure msmtp with a `~/.msmtprc` file:
68
69     account default
70          host smtp.mail.drexel.edu
71          from <your-username>@drexel.edu
72
73     # use STMP authentication
74          auth on
75          user <your-username>
76          password <your-password>
77
78     # use TLS encryption
79          tls on
80          tls_trust_file /etc/ssl/certs/ca-certificates.crt
81
82 To find information on a given SMTP server from the command line, use
83
84     $ msmtp --host=smtp.some.domain --server-info
85
86 The same security issues with plain text passwords apply to
87 `.msmtprc`, so `chmod 600` it, or possibly remove your password
88 information entirely.
89
90 Usage
91 =====
92
93 There's list of basic shortcuts across the top of the Mutt screen.
94 Most importantly, `?:Help`, which will give a list of all the current
95 shortcuts.
96
97 Tutorial
98 ========
99
100 An excellent tutorial page is [my first mutt][mfm].
101
102 Multiple accounts
103 =================
104
105 I finally had some time to play around and get Drexel mail and Gmail
106 working at the same time.  The basic setup is the same as above, using
107 msmtp to send the mail and Mutt's built in IMAP capability to get it
108 from the servers.
109
110 First configure msmtp with:
111
112     # ~/.msmtp
113     # Mostly from Peter Garrett's examples
114     #  https://lists.ubuntu.com/archives/ubuntu-users/2007-September/122698.html
115     # Accounts from Scott Robbins' `A Quick Guide to Mutt'
116     #  http://home.nyc.rr.com/computertaijutsu/mutt.html
117
118     account drexel
119          host smtp.mail.drexel.edu
120          from <drexel-from-address>@drexel.edu
121          auth on
122          user <drexel-username>
123          password <drexel-password>
124          tls on
125          #tls_trust_file /etc/ssl/certs/ca-certificates.crt
126          tls_trust_file /etc/pki/tls/cert.pem
127
128     account gmail
129          host smtp.gmail.com
130          from <gmail-from-address>@gmail.com
131          user <gmail-from-address>@gmail.com
132          password <gmail password>
133          port 587
134          auth on
135          tls on
136          tls_trust_file /etc/pki/tls/cert.pem
137
138     account default : drexel
139
140 This sets msmtp up so it can connect to either mail
141 server. `<drexel-username>` is your username (`abc123`),
142 `<drexel-from-address>` can be the same as `<drexel-username>`, but
143 you can use any address you've set up as an alias.
144 `<gmail-from-address>@gmail.com` is your full gmail email address. The
145 `tls_trust_file` line depends on your distribution.  For Debian-based
146 distributions, use the `ca-certificates.crt` line; and for Red
147 Hat-based distributions, use the `cert.pem` line.  I don't know where
148 the certificate information is stored for other distributions, but
149 googling about should find it.
150
151 Then configure mutt with
152
153     # ~/.muttrc
154
155     mailboxes imaps://<drexel-username>@imap.mail.drexel.edu imaps://<gmail-username>@gmail.com@imap.gmail.com
156
157     source ~/.mutt/common
158     source ~/.mutt/drexel
159
160     # from http://wiki.mutt.org/?MuttGuide/UseIMAP
161     # account-hook to set up connection parameters (username, password, etc.)
162     # and folder hook for everything else.
163     account-hook . 'set imap_user=<drexel-username>@drexel.edu imap_pass="<drexel-password>"'
164     account-hook imaps://<drexel-username>@imap.mail.drexel.edu \
165             'set imap_user=<drexel-username>@drexel.edu imap_pass="<drexel-password>"'
166     account-hook imaps://<gmail-username>@gmail.com@imap.gmail.com \
167             'set imap_user=<gmail-username>@gmail.com imap_pass="<gmail-password>"'
168     folder-hook imaps://<drexel-username>@imap.mail.drexel.edu 'source ~/.mutt/drexel'
169     folder-hook imaps://<gmail-username>@gmail.com@imap.gmail.com 'source ~/.mutt/gmail'
170
171     # switch FROM field so msmtp changes sending account
172     # http://home.nyc.rr.com/computertaijutsu/mutt.html
173     macro generic "<esc>1" ":set from='<drexel-from-address>@drexel.edu'"
174     macro generic "<esc>2" ":set from='<gmail-username>@gmail.com'"
175     # no send2-hook in version 1.4.2.2i
176     send-hook '~f <drexel-from-address>@drexel.edu' 'set sendmail="/usr/local/bin/msmtp "'
177     send-hook '~f <gmail-username>@gmail.com' 'set sendmail="/usr/local/bin/msmtp -a gmail"'
178     #send-hook '~f <drexel-from-address>@drexel.edu' 'set sendmail="/usr/bin/msmtp "'
179     #send-hook '~f <gmail-username>@gmail.com' 'set sendmail="/usr/bin/msmtp -a gmail"'
180
181     set use_from=yes # required so msmtp knows which account to use to send mails
182
183 This sets up your two mailboxes (drexel and gmail) where you can
184 recieve mail.  It also sets up methods for switching between the two
185 accounts.  To ease in configuring the two accounts, we split most of
186 the configuration details into `~/.mutt/common`, `~/.mutt/drexel`, and
187 `~/.mutt/gmail`.  Sourcing common brings in some configuration
188 commands shared by both accounts.  The `drexel` and `gmail` files
189 contain account-specific configuration commands.  All the password
190 information is in `.muttrc` and `.msmtprc` though, so be sure to
191 `chmod 600` them.  Make sure you get the path to `msmtp` right for
192 your system (`which msmtp` should find it).
193
194 Note that I removed the `folder-hook . 'source ~/.mutt/drexel'` line
195 that had been in my previous version.  This line was stupid and
196 switched back to my drexel settings whenever I left my Gmail inbox
197 (say for my Gmail `Sent Mail` box).  Without it, Mutt has been
198 behaving much more intuitively.
199
200 The specific configuration files are:
201
202 The common configuration (these are all optional).
203
204     #~/.mutt/common
205     set realname="<your-realname>"
206
207     set move=no       # stop asking to "move read messages to mbox"
208
209     set mail_check=600 # check for new mail every 10 minutes when user is active
210     set timeout=600   # check for new mail every 10 minutes when user is not active
211
212     set editor="/usr/bin/emacs -nw"    # use emacs as the editor
213     set edit_headers                   # editable headers
214
215 The Drexel setup
216
217     #~/.mutt/drexel
218     # Drexel information
219
220     # Drexel mail server addresses from
221     #  http://www.drexel.edu/IRT/support/ConfigureEmail.html
222     # email server location
223     set spoolfile=imaps://<drexel-username>@imap.mail.drexel.edu:993/INBOX
224     set folder=imaps://<drexel-username>@imap.mail.drexel.edu:993/
225
226     # save copies of sent emails to the ${folder}Sent directory
227     # the '+' expands to $folders (like '~' to $HOME in the bash shell)
228     set record=+Sent
229
230     # use msmtp to send outgoing mail to the mailserver
231     # see ~/.msmtp for configuration
232     set sendmail=/usr/local/bin/msmtp
233
234     set from="<drexel-from-address>@drexel.edu"
235
236 And the Gmail setup
237
238     # Gmail information
239
240     # Gmail mail server addresses from
241     #  http://mail.google.com/support/bin/answer.py?answer=78799
242     # email server location
243     set spoolfile=imaps://<gmail-username>@gmail.com@imap.gmail.com:993/INBOX
244     set folder=imaps://<gmail-username>@gmail.com@imap.gmail.com:993/
245
246     # gmail does this automatically
247     unset record
248
249     # use msmtp to send outgoing mail to the mailserver
250     # see ~/.msmtp for configuration
251     set sendmail="/usr/local/bin/msmtp -a gmail"
252
253     set from="<gmail-username>@gmail.com"
254
255 Firing up `mutt` takes you to your Drexel inbox like you're used to.
256 You can change directories like your used to with `c`.  You switch
257 accounts with `c TAB TAB`.  The first tab lists all the mailboxes in
258 your Drexel account, and the second lists all of your available
259 accounts (mailboxes).
260
261 Strangely (I haven't figured out why yet), `c TAB` from gmail also
262 lists the *drexel* directories.  No problem though, you can get a list
263 of gmail directories with `c +TAB TAB TAB` from gmail (I also don't
264 understand what the second `TAB` does).
265
266 Anyhow, that should get people started.
267
268 POP
269 ===
270
271 I just added my Comcast email account (a necessary administrative
272 evil) to the above configuration.  Comcast doesn't supply an [[IMAP]]
273 interface, so we're forced to fall back on [[POP]].  Luckily, that
274 doesn't change much of the configuration, which consisted of creating
275 a `.mutt/comcast` file:
276
277     # Comcast information
278
279     # Comcast mail server addresses from
280     #  http://www.comcast.com/customers/faq/FaqDetails.ashx?Id=2165
281     # Ports from
282     #  http://www.comcast.com/customers/faq/FaqDetails.ashx?ID=2288
283     # email server location
284     set spoolfile=pops://<comcast-username>@mail.comcast.net:110/INBOX
285     set folder=pops://<comcast-username>@mail.comcast.net:110/
286
287     # gmail does this automatically
288     unset record
289
290     # use msmtp to send outgoing mail to the mailserver
291     # see ~/.msmtp for configuration
292     set sendmail="/usr/local/bin/msmtp -a gmail"
293
294     set from="<gmail-username>@gmail.com"
295
296     set nopop_delete
297     set pop_checkinterval="600"
298
299 Where the gmail stuff is because I'm sending mail using Gmail when I'm
300 looking at my Comcast account.  This avoids using Comcast as much as
301 possible ;).  Note that `<comcast-username>` is everything before the
302 `@` in your Comcast email address.
303
304 I then adjust my `.muttrc` file by adding Comcast to my list of
305 mailboxes:
306
307     mailboxes imaps://<drexel-username>@imap.mail.drexel.edu imaps://<gmail-username>@gmail.com@imap.gmail.com pops://<comcast-username>@mail.comcast.net
308
309 in a single long line. I also added account and folder hooks:
310
311     account-hook pops://<comcast-username>@mail.comcast.net \
312             'set pop_user=<comcast-username> pop_pass="<comcast-password>"'
313     folder-hook imaps://<comcast-username>@imap.comcast.net 'source ~/.mutt/comcast'
314
315 And that seems to handle it…
316
317 PGP
318 ===
319
320 [[PGP]] is a encryption and authentication system often used for
321 protecting email.  The [[GnuPG]] implementation can be used with Mutt
322 to send secure, authenticated emails between capable parties.
323
324 Once you've got a key set up, determine the key ID for your pair with
325
326     $ gpg --list-keys --keyid-format 0xlong
327     /home/user/.gnupg/pubring.gpg
328     -----------------------------
329     pub   1024D/0xFC29BDCDF15F5BE8 2008-08-09 [expires: 2009-08-09]
330     …
331
332 Where `0xFC29BDCDF15F5BE8` is my long key ID (I don't understand the
333 difference between the long and short keys, but I figure the longer
334 one must be more specific, and since I only have to enter it once for
335 Mutt, I chose the longer key.)
336
337 Then, tell Mutt how to use `gpg`, adding
338
339     source ~/.mutt/pgp
340
341 to your `.muttrc` file and creating `~/.mutt/pgp` as follows
342 (replacing my key ID with your own)
343
344     # from Justin R. Miller's
345     # `Everything You Need To Know To Start Using GnuPG with Mutt'
346     # http://codesorcery.net/old/mutt/mutt-gnupg-howto
347
348     set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
349     set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f"
350     set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
351     set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
352     set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
353     set pgp_encrypt_only_command="/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0xFC29BDCDF15F5BE8 -- -r %r -- %f"
354     set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0xFC29BDCDF15F5BE8 -- -r %r -- %f"
355     set pgp_import_command="gpg --no-verbose --import -v %f"
356     set pgp_export_command="gpg --no-verbose --export --armor %r"
357     set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r"
358     set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r"
359     set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r"
360     set pgp_autosign=yes
361     set pgp_sign_as=0xFC29BDCDF15F5BE8
362     set pgp_replyencrypt=yes
363     set pgp_timeout=1800
364     set pgp_good_sign="^gpg: Good signature from"
365
366 The above file autosigns all your sent emails (`set
367 pgp_autosign=yes`), but you can obviously turn that off if you would
368 like.  To change signing/encryption on an email, use the `p` key from
369 the compose view (the screen shown after you have finished editing a
370 new e-mail; thank, you [Chad Perrin][compose-view-p]).
371
372 Browsing email with links
373 =========================
374
375 Usually mutt is pretty good about handling HTML in emails.  When you
376 get emails that are obviously HTML, `v` will take you to the
377 attachment list (which should show the email as type `text/html`), and
378 enter will open the email in your browser ([[w3m]], right?).
379
380 Sometimes you get `text/plain` emails with URLs in them, or maybe the
381 above procedure just isn't working.  In that case, add
382
383     macro pager \cb <pipe-entry>'w3m'<enter> 'Follow links in w3m'
384
385 somewhere in your mutt configuration files (thank you, [Bruno
386 Postle][links]).  Then pressing `Ctrl-b` will pipe the email you're
387 looking at into w3m.  Pressing `:` in w3m will scan the document for
388 URL-like strings and make them browsable.
389
390 Folder size in status bar
391 =========================
392
393 Add the folder size to the status bar by adding `%l` or `%L` to
394 `status_format` in your `~/.muttrc` file.  For example
395
396     set status_format="-%r-Mutt: %f %L"
397
398
399 [Mutt]: http://www.mutt.org/
400 [MUA]: http://en.wikipedia.org/wiki/Email_client
401 [msmtp]: http://msmtp.sourceforge.net/
402 [mfm]: http://mutt.blackfish.org.uk/
403 [GnuPG]: http://www.gnupg.org/
404 [compose-view-p]: http://blogs.techrepublic.com.com/security/?p=413
405 [links]: http://mutt.blackfish.org.uk/following-links/
406
407 [[!tag tags/tools]]