From: W. Trevor King Date: Wed, 4 Feb 2009 18:06:00 +0000 (-0500) Subject: posts:mutt: copy post over from Drexel Liki. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4104a540dfec4cb2f4db6e983763d12d4374b195;p=blog.git posts:mutt: copy post over from Drexel Liki. This is my http://www.physics.drexel.edu/liki/index.php?title=Mutt&oldid=2213 translated into Markdown. I had been the only contributor to that liki page at that point. --- diff --git a/posts/Mutt.mdwn b/posts/Mutt.mdwn new file mode 100644 index 0000000..2604086 --- /dev/null +++ b/posts/Mutt.mdwn @@ -0,0 +1,407 @@ +[[!meta date="2009-02-04 13:06:00"]] + +[Mutt][] is a simple, configurable mail user agent [MUA][]/email +client. I got tired of using webmail to check my email, so I got Mutt +set up on my computer instead. Mutt is intended to be an email +browser, so most versions don't have built in [[SMTP]] support. For a +simple setup, you can use an external SMTP client like [msmtp][], +which is how we'll do it in the examples below. + +Install +======= + +For Debian-type distros (e.g. Debian, Ubuntu, …), you can install Mutt +and msmpt with + + $ apt-get install mutt msmtp + +Configure +========= + +You configure Mutt with the file `~/.muttrc`. To set it up with the +Drexel email system, I looked up the server addresses, and created the +`.muttrc` file: + + # login information + set imap_user='@drexel.edu' + set imap_pass='' + set from="@drexel.edu" + set use_from=yes # required so msmtp knows which account to use to send mails + + # setting your realname is optional, but drexel addresses can be cryptic... + set realname="" + + # email server location + set spoolfile=imaps://@imap.mail.drexel.edu:993/INBOX + set folder=imaps://@imap.mail.drexel.edu:993/ + + # use msmtp for sending mail + set sendmail=/usr/bin/msmtp # Debian-style system path, yours may be different + + # save copies of sent email to the ${folder}Sent directory + # the '+' expands to $folders (like '~' to $HOME in bash) + set record=+Sent + + set mail_check=600 # check for new mail every 10 minutes when user is active + set timeout=600 # check for new mail every 10 min. when user is not active + + set editor="/usr/bin/emacs -nw" # use emacs for writing emails + set edit_headers # allow editing headers while you're in emacs + +Since this file contains your password, you should not allow other +users to read it. + + $ chmod 600 ~/.muttrc + +This still isn't terribly secure, so you could remove the password +line entirely, in which case Mutt prompts you for it when it tries to +log in (just like webmail does). + +The `mail_check` and `timeout` settings set up how often Mutt checks +for new mail, which I've set to be pretty slow. You can type `$` to +sync, whenever you want to send outgoing mail or check for new mail. + +Googling `.muttrc` should turn up tons of other goodies, or try `man +muttrc`. + +You also have to configure msmtp with a `~/.msmtprc` file: + + account default + host smtp.mail.drexel.edu + from @drexel.edu + + # use STMP authentication + auth on + user + password + + # use TLS encryption + tls on + tls_trust_file /etc/ssl/certs/ca-certificates.crt + +To find information on a given SMTP server from the command line, use + + $ msmtp --host=smtp.some.domain --server-info + +The same security issues with plain text passwords apply to +`.msmtprc`, so `chmod 600` it, or possibly remove your password +information entirely. + +Usage +===== + +There's list of basic shortcuts across the top of the Mutt screen. +Most importantly, `?:Help`, which will give a list of all the current +shortcuts. + +Tutorial +======== + +An excellent tutorial page is [my first mutt][mfm]. + +Multiple accounts +================= + +I finally had some time to play around and get Drexel mail and Gmail +working at the same time. The basic setup is the same as above, using +msmtp to send the mail and Mutt's built in IMAP capability to get it +from the servers. + +First configure msmtp with: + + # ~/.msmtp + # Mostly from Peter Garrett's examples + # https://lists.ubuntu.com/archives/ubuntu-users/2007-September/122698.html + # Accounts from Scott Robbins' `A Quick Guide to Mutt' + # http://home.nyc.rr.com/computertaijutsu/mutt.html + + account drexel + host smtp.mail.drexel.edu + from @drexel.edu + auth on + user + password + tls on + #tls_trust_file /etc/ssl/certs/ca-certificates.crt + tls_trust_file /etc/pki/tls/cert.pem + + account gmail + host smtp.gmail.com + from @gmail.com + user @gmail.com + password + port 587 + auth on + tls on + tls_trust_file /etc/pki/tls/cert.pem + + account default : drexel + +This sets msmtp up so it can connect to either mail +server. `` is your username (`abc123`), +`` can be the same as ``, but +you can use any address you've set up as an alias. +`@gmail.com` is your full gmail email address. The +`tls_trust_file` line depends on your distribution. For Debian-based +distributions, use the `ca-certificates.crt` line; and for Red +Hat-based distributions, use the `cert.pem` line. I don't know where +the certificate information is stored for other distributions, but +googling about should find it. + +Then configure mutt with + + # ~/.muttrc + + mailboxes imaps://@imap.mail.drexel.edu imaps://@gmail.com@imap.gmail.com + + source ~/.mutt/common + source ~/.mutt/drexel + + # from http://wiki.mutt.org/?MuttGuide/UseIMAP + # account-hook to set up connection parameters (username, password, etc.) + # and folder hook for everything else. + account-hook . 'set imap_user=@drexel.edu imap_pass=""' + account-hook imaps://@imap.mail.drexel.edu \ + 'set imap_user=@drexel.edu imap_pass=""' + account-hook imaps://@gmail.com@imap.gmail.com \ + 'set imap_user=@gmail.com imap_pass=""' + folder-hook imaps://@imap.mail.drexel.edu 'source ~/.mutt/drexel' + folder-hook imaps://@gmail.com@imap.gmail.com 'source ~/.mutt/gmail' + + # switch FROM field so msmtp changes sending account + # http://home.nyc.rr.com/computertaijutsu/mutt.html + macro generic "1" ":set from='@drexel.edu'" + macro generic "2" ":set from='@gmail.com'" + # no send2-hook in version 1.4.2.2i + send-hook '~f @drexel.edu' 'set sendmail="/usr/local/bin/msmtp "' + send-hook '~f @gmail.com' 'set sendmail="/usr/local/bin/msmtp -a gmail"' + #send-hook '~f @drexel.edu' 'set sendmail="/usr/bin/msmtp "' + #send-hook '~f @gmail.com' 'set sendmail="/usr/bin/msmtp -a gmail"' + + set use_from=yes # required so msmtp knows which account to use to send mails + +This sets up your two mailboxes (drexel and gmail) where you can +recieve mail. It also sets up methods for switching between the two +accounts. To ease in configuring the two accounts, we split most of +the configuration details into `~/.mutt/common`, `~/.mutt/drexel`, and +`~/.mutt/gmail`. Sourcing common brings in some configuration +commands shared by both accounts. The `drexel` and `gmail` files +contain account-specific configuration commands. All the password +information is in `.muttrc` and `.msmtprc` though, so be sure to +`chmod 600` them. Make sure you get the path to `msmtp` right for +your system (`which msmtp` should find it). + +Note that I removed the `folder-hook . 'source ~/.mutt/drexel'` line +that had been in my previous version. This line was stupid and +switched back to my drexel settings whenever I left my Gmail inbox +(say for my Gmail `Sent Mail` box). Without it, Mutt has been +behaving much more intuitively. + +The specific configuration files are: + +The common configuration (these are all optional). + + #~/.mutt/common + set realname="" + + set move=no # stop asking to "move read messages to mbox" + + set mail_check=600 # check for new mail every 10 minutes when user is active + set timeout=600 # check for new mail every 10 minutes when user is not active + + set editor="/usr/bin/emacs -nw" # use emacs as the editor + set edit_headers # editable headers + +The Drexel setup + + #~/.mutt/drexel + # Drexel information + + # Drexel mail server addresses from + # http://www.drexel.edu/IRT/support/ConfigureEmail.html + # email server location + set spoolfile=imaps://@imap.mail.drexel.edu:993/INBOX + set folder=imaps://@imap.mail.drexel.edu:993/ + + # save copies of sent emails to the ${folder}Sent directory + # the '+' expands to $folders (like '~' to $HOME in the bash shell) + set record=+Sent + + # use msmtp to send outgoing mail to the mailserver + # see ~/.msmtp for configuration + set sendmail=/usr/local/bin/msmtp + + set from="@drexel.edu" + +And the Gmail setup + + # Gmail information + + # Gmail mail server addresses from + # http://mail.google.com/support/bin/answer.py?answer=78799 + # email server location + set spoolfile=imaps://@gmail.com@imap.gmail.com:993/INBOX + set folder=imaps://@gmail.com@imap.gmail.com:993/ + + # gmail does this automatically + unset record + + # use msmtp to send outgoing mail to the mailserver + # see ~/.msmtp for configuration + set sendmail="/usr/local/bin/msmtp -a gmail" + + set from="@gmail.com" + +Firing up `mutt` takes you to your Drexel inbox like you're used to. +You can change directories like your used to with `c`. You switch +accounts with `c TAB TAB`. The first tab lists all the mailboxes in +your Drexel account, and the second lists all of your available +accounts (mailboxes). + +Strangely (I haven't figured out why yet), `c TAB` from gmail also +lists the *drexel* directories. No problem though, you can get a list +of gmail directories with `c +TAB TAB TAB` from gmail (I also don't +understand what the second `TAB` does). + +Anyhow, that should get people started. + +POP +=== + +I just added my Comcast email account (a necessary administrative +evil) to the above configuration. Comcast doesn't supply an [[IMAP]] +interface, so we're forced to fall back on [[POP]]. Luckily, that +doesn't change much of the configuration, which consisted of creating +a `.mutt/comcast` file: + + # Comcast information + + # Comcast mail server addresses from + # http://www.comcast.com/customers/faq/FaqDetails.ashx?Id=2165 + # Ports from + # http://www.comcast.com/customers/faq/FaqDetails.ashx?ID=2288 + # email server location + set spoolfile=pops://@mail.comcast.net:110/INBOX + set folder=pops://@mail.comcast.net:110/ + + # gmail does this automatically + unset record + + # use msmtp to send outgoing mail to the mailserver + # see ~/.msmtp for configuration + set sendmail="/usr/local/bin/msmtp -a gmail" + + set from="@gmail.com" + + set nopop_delete + set pop_checkinterval="600" + +Where the gmail stuff is because I'm sending mail using Gmail when I'm +looking at my Comcast account. This avoids using Comcast as much as +possible ;). Note that `` is everything before the +`@` in your Comcast email address. + +I then adjust my `.muttrc` file by adding Comcast to my list of +mailboxes: + + mailboxes imaps://@imap.mail.drexel.edu imaps://@gmail.com@imap.gmail.com pops://@mail.comcast.net + +in a single long line. I also added account and folder hooks: + + account-hook pops://@mail.comcast.net \ + 'set pop_user= pop_pass=""' + folder-hook imaps://@imap.comcast.net 'source ~/.mutt/comcast' + +And that seems to handle it… + +PGP +=== + +[[PGP]] is a encryption and authentication system often used for +protecting email. The [[GnuPG]] implementation can be used with Mutt +to send secure, authenticated emails between capable parties. + +Once you've got a key set up, determine the key ID for your pair with + + $ gpg --list-keys --keyid-format 0xlong + /home/user/.gnupg/pubring.gpg + ----------------------------- + pub 1024D/0xFC29BDCDF15F5BE8 2008-08-09 [expires: 2009-08-09] + … + +Where `0xFC29BDCDF15F5BE8` is my long key ID (I don't understand the +difference between the long and short keys, but I figure the longer +one must be more specific, and since I only have to enter it once for +Mutt, I chose the longer key.) + +Then, tell Mutt how to use `gpg`, adding + + source ~/.mutt/pgp + +to your `.muttrc` file and creating `~/.mutt/pgp` as follows +(replacing my key ID with your own) + + # from Justin R. Miller's + # `Everything You Need To Know To Start Using GnuPG with Mutt' + # http://codesorcery.net/old/mutt/mutt-gnupg-howto + + set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f" + set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f" + set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f" + set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f" + set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f" + 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" + 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" + set pgp_import_command="gpg --no-verbose --import -v %f" + set pgp_export_command="gpg --no-verbose --export --armor %r" + set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r" + set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r" + set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r" + set pgp_autosign=yes + set pgp_sign_as=0xFC29BDCDF15F5BE8 + set pgp_replyencrypt=yes + set pgp_timeout=1800 + set pgp_good_sign="^gpg: Good signature from" + +The above file autosigns all your sent emails (`set +pgp_autosign=yes`), but you can obviously turn that off if you would +like. To change signing/encryption on an email, use the `p` key from +the compose view (the screen shown after you have finished editing a +new e-mail; thank, you [Chad Perrin][compose-view-p]). + +Browsing email with links +========================= + +Usually mutt is pretty good about handling HTML in emails. When you +get emails that are obviously HTML, `v` will take you to the +attachment list (which should show the email as type `text/html`), and +enter will open the email in your browser ([[w3m]], right?). + +Sometimes you get `text/plain` emails with URLs in them, or maybe the +above procedure just isn't working. In that case, add + + macro pager \cb 'w3m' 'Follow links in w3m' + +somewhere in your mutt configuration files (thank you, [Bruno +Postle][links]). Then pressing `Ctrl-b` will pipe the email you're +looking at into w3m. Pressing `:` in w3m will scan the document for +URL-like strings and make them browsable. + +Folder size in status bar +========================= + +Add the folder size to the status bar by adding `%l` or `%L` to +`status_format` in your `~/.muttrc` file. For example + + set status_format="-%r-Mutt: %f %L" + + +[Mutt]: http://www.mutt.org/ +[MUA]: http://en.wikipedia.org/wiki/Email_client +[msmtp]: http://msmtp.sourceforge.net/ +[mfm]: http://mutt.blackfish.org.uk/ +[GnuPG]: http://www.gnupg.org/ +[compose-view-p]: http://blogs.techrepublic.com.com/security/?p=413 +[links]: http://mutt.blackfish.org.uk/following-links/ + +[[!tag tags/tools]]