Jiff Slater
🤔 About
✍️ Contact
30 Jul 2021
These articles have been archived. You may find them useful but I am no longer offering support for them. Check out my latest articles on plkt.io.
Adding additional email accounts to your email setup
15 July 2008

Upon hearing that my college offers email access through its POP and SMTP servers, I immediately set out to integrate it into my email setup.

Today I will show you how.

Note: I use Mutt to read my email, getmail to retrieve my mail, procmail to filter my mail, and msmtp to send my mail.  This tutorial can also be used for configuring a new account in a similar setup.

Because my email setup is quite complicated, this will take longer to configure than it would with a mail client such as Thunderbird or Outlook.  However, I enjoy the level of customization offered by such a setup.

1. Setting up getmail

First, make sure that you have the .getmail directory in your home dir.  If not, create it (mkdir -m 700 ~/.getmail)

~ %  ls -la | grep getmail
drwx------  2 antony antony 4.0K 2008-07-09 17:30 .getmail/

Change to the .getmail directory and create the account file.

~ %  cd .getmail
.getmail %  touch getmailrc_college

Edit the file.  Note: !$ means the last space separated word from the previous command, in this case “getmailrc_college”

.getmail %  vim !$
1 [retriever]
2 type = SimplePOP3SSLRetriever
3 server = pop.college.edu
4 username = name
5 port = 995
6 password = password
8 [destination]
9 type = MDA_external
10 path = /usr/bin/procmail

Change the file permissions (read, write for user)

.getmail %  chmod 600 getmailrc_college

2. Setting up procmail

All we have to do is add a filter for email from the college domain address.  Note: Because my college email address can have a number 0-9 appended to the end of the username, I used the regex [0-9], which matches one digit.gt

.getmail %  cd
~ % vim ~/.procmailrc
20 :0
21 * ^TO_name[0-9]@college\.edu
22 college/

3. Setting up msmtp

This is the most involved step.

Security is always first, so check the available authentication options of the server.  I’ll use Gmail as an example (yep, straight from the manpage).

~ %  msmtp --serverinfo --host=smtp.gmail.com --tls=on --port=587 --tls-certcheck=off
SMTP server at smtp.gmail.com (yw-in-f109.google.com []), port 587:
    mx.google.com ESMTP 6sm2875694ywp.3
TLS certificate information:
        Common Name: smtp.gmail.com
        Organization: Google Inc
        Locality: Mountain View
        State or Province: California
        Country: US
        Common Name: Thawte Premium Server CA
        Organization: Thawte Consulting cc
        Organizational unit: Certification Services Division
        Locality: Cape Town
        State or Province: Western Cape
        Country: ZA
    SIZE 28311552:
        Maximum message size is 28311552 bytes = 27.00 MB
        Support for TLS encryption via the STARTTLS command
        Supported authentication methods:

The important part here is the issuer of the certificate (shown by the Common Name). In this case, the issuer is “Thawte Premium Server CA” so we need to download that certificate from the Thawte website and place it in our ~/.certs directory.

~ %  cd ~/.certs
.certs %  unzip thawte-roots.zip -d thawte [truncated output]
.certs %  cd thawte
thawte %  cd Thawte\ Server\ Roots
Thawte Server Roots %  ls
Thawte Server Roots.txt    ThawtePremiumServerCA.cer      ThawteServerCA.509  ThawteServerCA_b64.txt
ThawtePremiumServerCA.509  ThawtePremiumServerCA_b64.txt  ThawteServerCA.cer
Thawte Server Roots %  cp ThawtePremiumServerCA.cer ../../
Thawte Server Roots %  cd !$
.certs %  ls
ThawtePremiumServerCA.cer  thawte/  thawte-roots.zip
.certs %  rm -r thawte*

Now you can use TLS, so edit your ~/.msmtprc file

.certs %  cd
~ % vim .msmtprc
21 account college
22 host smtp.college.edu
23 from name@college.edu
24 user name@college.edu
25 password somepassword
26 port 587
27 auth on
28 tls on
29 tls_trust_file /home/antony/.certs/ThawtePremiumServerCA.crt

4. Next, configure Mutt for account switching.

~ %  cd .mutt

Create a profile for each account. Because I include my email address in my signature, I have to switch to a different signature when I change email accounts.  The unmy_hdr resets the my_hdr variable, which is then defined by the following my_hdrset sendmail= tells Mutt to use a different sendmail command.  And set compose_format changes the display at the bottom of the screen so I know which mail account I am using.

~ % vim muttrc.local1
  1 # default Mutt profile
  2 set signature="~/.signature"
  3 unmy_hdr
  4 my_hdr From: Antony Jepson <email@gmail.com>
  5 my_hdr Reply-To: Antony Jepson <email@gmail.com>
  6 set sendmail="/usr/bin/msmtp --account default"
  7 set compose_format="-- default Mutt: Compose [Approx. msg size: %l] Atts:%a]%>-"
~ % vim muttrc.local2
  1 # college Mutt profile
  2 set signature="~/.signature2"
  3 unmy_hdr
  4 my_hdr From: First Last <name@college.edu>
  5 my_hdr Reply-To: First Last <name@college.edu>
  6 set sendmail="/usr/bin/msmtp --account college"
  7 set compose_format="-- college Mutt: Compose [Approx. msg size: %l] Atts:%a]%>-"

All we have to do is add a keyboard-binding that will source each different profile.  This configuration will switch to a different profile when I press Control-q and Control-w.

.mutt %  vim macros.rc
  4 macro index "\Cq" ":source ~/.mutt/muttrc.local1\n" "Load default profile"
  5 macro index "\Cw" ":source ~/.mutt/muttrc.local2\n" "Load college profile"

And, if you are not already sourcing this rc file in the default mutt configuration, add it.

.mutt %  echo "source ~/.mutt/macros.rc" >> ~/.mutt/muttrc

5. Finally, because I will be using this address for the next four years, I’ll add it to my gpg key.

.mutt %  cd
~ %  gpg --edit-key Antony\ Jepson [truncated output]
Command> adduid
Real name: Antony Jepson
Email address: name@college.edu
Comment: College email
You selected this USER-ID:
    "Antony Jepson (College email) <name@college.edu>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

You need a passphrase to unlock the secret key for
    user: "Antony Jepson (College email) <name@college.edu>"
    Passphrase: somepassphrase
Command> save

Finally, send your updated key to the keysever.

~ %  gpg --send-key name@college.edu

And that’s it.  You now (or I, at least) have a working, secure, additional, Mutt-enabled, email account!

I’m still getting used to the WYSIWYG WordPress formatting toolbar, I’ll make (hopefully better) use of it as I write more posts.