Tuesday, November 12, 2013

Using Gmail via Mutt

Often, using a command line mail client is much more efficient than e.g. a web-based one. Some example cases:
  • If, like me, you have a Gmail account, it is, as far as I know, not possible to easily use the Gnu Privacy Guard without resorting to encrypting files "by hand" and then uploading them as attachments. It wouldn't make much sense anyway, decrypting stuff on Google's servers for all of the NSA to see.
  • Another use case for a command line mail client is when you want to send mail from within a script. E.g. the following bash script fragment sends a message with an attachment and a subject line:
    mutt -a picture.jpg -s "a subject" jj@gmail.com <<EOF
      As promised, the picture is attached.
      Blah blah.
    EOF
    
    where mutt refers to the, imo, best command line mail client program.

Luckily, you can use the Gmail service as an IMAP server for your preferred command line mail client.

Below are the instructions to set up mutt such that it will use Gmail to send and receive messages. Note that any message sent/received will also be available on line, i.e. in the folders of your gmail account.

  1. First, you need to install mutt. In ubuntu
    sudo apt-get install mutt
    
    On my 13.10 ubuntu system, also the mail server postfix was installed and the system prompted for postfix configuration options. Since I was not going to use postfix, I selected 'no configuration'.
  2. Next you fill in the configuration file called .muttrc in your home directory. The instructions can be found on the GMailOverIMAP page of the Mutt developer resources site and are merely repeated here.
    set imap_user = 'yourusername@gmail.com'
    set imap_pass = 'yourpassword'
    
    set spoolfile = imaps://imap.gmail.com/INBOX
    set folder = imaps://imap.gmail.com/
    set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"
    set postponed="imaps://imap.gmail.com/[Gmail]/Drafts"
    
That's it.

No comments:

Post a Comment