The Lumber Room

"Consign them to dust and damp by way of preserving them"

Using Gmail with mutt, the minimal way (IMAP update)

with 74 comments

As Gmail has IMAP access, it is fairly trivial to get it working with mutt. First, if you’re on Ubuntu/Debian, run sudo apt-get install openssl mutt to get mutt if you don’t already have it. Then, just put the following lines into your ~/.muttrc:

set imap_user = "username@gmail.com"
set imap_pass = "password"

set smtp_url = "smtp://username@smtp.gmail.com:587/"
set smtp_pass = "password"
set from = "username@gmail.com"
set realname = "Your Real Name"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"

set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set move = no

Make sure your ~/.muttrc isn’t world-readable; it contains your password. (Alternatively, you can leave them out and mutt will prompt you for the password each time.) Also, if you copy-paste from the above, make sure that you have only “normal” quotes, not “smart quotes” which WordPress might have inserted here into this post.

[Other things I have:

set sort = 'threads'
set sort_aux = 'last-date-received'
set imap_check_subscribed

ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc

I did not include above to justify the “minimal” :)]

Things work perfectly as you would expect them.
One thing to note is that the full headers will still contain the hostname of the computer you send messages from. I have not figured a way of hiding this, and perhaps it shouldn’t be possible.

The End

If for some reason you want to use POP, read on. And tell me why you would want to use POP. The rest of the post is an old version, which i had written before Gmail supported IMAP.

Old Stuff
There is a guide here, which is the first Google result on searching for the keywords Gmail, mutt and Ubuntu in any order, but I would advise against it: it does too much unnecessary stuff using too many unnecessary programs (okay if you don’t care), and involves putting your username and password in a world-readable file (not okay).

There is a guide here, but that site seems down, and so I guess it’s likely to be down again (a DynDNS domain; could be someone’s house), so putting a (fuller) guide here:

First, run sudo apt-get install openssl mutt

Next, in /etc/ssmtp/ssmtp.conf, put
mailhub=smtp.gmail.com:465
UseTLS=YES

Everything else seems to be optional.

Next, create a shell script with the contents
#!/bin/sh
/usr/sbin/ssmtp -au "gmail-address" -ap "password" $@
and put it somewhere in your path (~/bin/gmailout, say) and make it executable (chmod u+x ~/bin/gmailout, I mean) and make sure only you can read it! (chmod og-r ~/bin/gmailout).

Now in ~/.muttrc, put
set pop_host="pops://username:password@pop.gmail.com:995"
set pop_last
unset pop_delete #Just makes mutt not ask, GMail uses config option
set sendmail="~/bin/gmailout"
set write_bcc=no #Important; sSMTP makes bcc non-blind otherwise

and you’re set (remember to make this world-unreadable too: chmod og-rw ~/.muttrc)

You can start mutt, and hit “G” (uppercase G) whenever you want to fetch mail. Can also put exec fetch-mail in ~/.muttrc to have it happen whenever you start mutt, but I find that irritating.

Problems with POP: Not that everything is perfect. I can’t have other mail-transport-agents like sendmail or postfix installed alongside ssmtp. I can’t figure out how to get my crontab reports sent to root, but they do go into ~/dead.letter :D
Also, with mutt I had the habit of adding a my_hdr bcc: my-email-address so that the mail I send is threaded along with the mail I receive (yaay, like Gmail), but somehow there seems to be simply no way of getting Gmail to give me, through POP, those messages I send using an external client. It’s a quirk [bug!] in the way Gmail implements POP. This I’ve fixed by setting mutt’s fcc to /var/mail/my-username, my mail folder. (Of course, if I were in the habit of moving mail to my mbox, I could fcc to mbox too.)
Apart from that, it works fine!

Advertisement

Written by S

Tue, 2007-07-31 at 02:16:03

74 Responses

Subscribe to comments with RSS.

  1. Sorry about the site being down. It is my home connection… and lately it’s been dropping out for about six hours every day. Anyway, glad you found it useful, and thanks for building on it, and posting it in a more reliable location :)

    mogrify

    Tue, 2007-07-31 at 17:27:14

  2. As the writer of the first site you discussed I would like to make a brief defence :-)

    1. When you say ‘it does too much unnecessary stuff using too many unnecessary programs’, this is the traditional way in Linux. i.e. One program to download, one program to filter, one program to read etc. Having said that now that IMAP has arrived at Gmail there is obviously a new way to do this, for Gmail at least.

    2.When you say ‘involves putting your username and password in a world-readable file’ I think you will find that all files that contain usernames and passwords in this walkthrough are set at 0600 or -rw——- which precludes ‘world’ readability. Certainly they are not encrypted, it depends how far you want to go. If you actually mean ‘transmitted over the Internet openly’ this is also untrue. fetchmail establishes an SSL connection to download the mail and msmtp estables a TLS connection to send the mail. Both use certificate verification.

    In the meantime all the best with spreading the IMAP / Gmail word, I will be switching there myself in the New Year.

    Regards,

    Andrew Strong
    http://people.aapt.net.au/~adjlstrong/mutt.html

    Andrew

    Tue, 2007-11-20 at 11:22:02

    • hi, when i try to send with the .muttrc settings. i get

      “No authenticators available”

      please help thanks

      calvin

      Sun, 2009-12-13 at 22:50:38

      • nevermind. mutt needs to be upgraded on my debian stable

        calvin

        Mon, 2009-12-14 at 13:30:24

  3. Heh sorry, didn’t mean any offence :)

    The emphasis was on the “minimal” in the title: Your guide is very helpful, but I felt that not everyone needs to have their editor set to vim, some colour scheme picked for them, and *procmail* set up! I also don’t quite understand the certificate stuff, actually… From my experience with using multiple computers, I have learnt to make only minimal changes to config files, and would generally prefer to muck around in as few places as possible, and not install much outside the distros packaging system. This also makes it easy to undo your changes if you decide at a later date that you don’t want to use mutt this way after all. I actually did spend some effort in achieving the “minimal”, and making sure each of those lines was really essential. (Of course, everything was done by mogrify the second-linked person, so no credit to me there).

    Note that this also doesn’t overwrite your existing colour settings or (more importantly) your existing fetchmail configuration or your existing procmail configuration, so you can continue using other (non-mutt) clients with whatever they did before. (This might be a good thing or bad) (And with your MTA configuration overwritten, it probably doesn’t make sense anyway — I should figure out whether it’s possible to make the changes in some file other than “/etc/ssmtp/ssmtp.conf” and use it *only* when ssmtp is being invoked from gmailout…) It may be the UNIX tradition to chain simple programs together, but I thought it was not my place to presume to give people a better mutt or procmail configuration than what they had, and only give the *diffs* necessary to get Gmail working.

    As for the “world-readable” comment, I probably missed the 0600 line, sorry about that. Ironically, I had myself forgotten to mention that (probably because I have a umask that makes all my files readable only by me, by default), I have fixed it now.

    Of course, all this is moot, as there is now no reason to use POP, anyway :)

    shreevatsa

    Tue, 2007-11-20 at 13:07:10

  4. We can certainly agree that there is little reason to use POP over SSL with Gmail now, although I personally will wait until the dust has settled until I change.

    I have just realised that you were talking about an older version of my page and the world readable charge may very well have been true of ssmtp. The guide has moved to memtp which appears more secure and a lot of the handholding has gone, as well as the Ubuntu nature of the page. I have myself gained a greater knowledge of the certificates involved and put more detail concerning this.

    But of course with IMAP available now all of this will fade ‘like tears in the rain’ as Roy said in Blade Runner :-)

    All the best,

    Andrew

    Andrew

    Tue, 2007-11-20 at 21:07:15

  5. Typo not memtp” msmtp

    Andrew

    Tue, 2007-11-20 at 21:08:08

  6. Great tutorial. Everything worked great except for where it says :

    set smtp_url = “smtp://username@gmail.com:587/”

    I had to change it to read :

    set smtp_url = “smtp://username@smtp.gmail.com:587/”

    Michael

    Wed, 2007-12-19 at 20:27:37

  7. Oops. This is what happens when you copy-paste “manually”, by retyping everything. I have updated the post, thanks!

    shreevatsa

    Thu, 2007-12-20 at 00:23:40

  8. Hello!

    I configured Mutt 1.5.16 for Gmail via IMAP. It works like a charm, except for one fact. Since I’ve got several IMAP folders for mailing lists (which are actually “labels” in Gmail, but via IMAP they’re seen as folders). When I press “c” to change folder, it doesn’t prompt me the ones with new messages in, as I remember it did with local folders. This can be kind of annoying, as it forces me to enter in every folder to see if there are new messages.

    Any hint?

    Thanks,
    Michele.

    Michele Beltrame

    Sun, 2008-03-16 at 19:42:41

  9. Hello,

    I’ll check, but in the meantime one thing that will probably work is to specify your mailboxes manually with “mailboxes +[Gmail]/label1 +[Gmail]/label2” etc.
    The manual also has a “set imap_check_subscribed” (new in 1.5.11) which looks like it might work.

    S

    Sun, 2008-03-16 at 22:23:16

  10. Both colutions seem to work perfectly. Thank you for the hint!

    Michele Beltrame

    Wed, 2008-03-19 at 09:44:06

  11. I’m wondering if the following is necessary as it seems to create duplicates for me:

    set record=”+[Gmail]/Sent Mail”

    deckrider

    Mon, 2008-05-19 at 16:39:06

  12. @deckrider: I think you are right. I had just assumed the duplicates were another Gmail quirk :)
    Thanks, I’ll remove it from the post.

    Shreevatsa

    Fri, 2008-05-23 at 10:31:49

  13. […] Using Mutt with Gmail (the minimal way) gives a copy-and-pasteable few lines on how to use Mutt with Gmail over IMAP. Easy to remember, but easier to look up and forget. Most of the other references are with fetchmail. The only thing I would add is to include other IMAP folders as mailboxes: […]

  14. Just a small remark on double quotes used in the above .muttrc snippet.
    Somehow ‘non-standard’ double quotes sneaked in here:

    set postponed=”+[Gmail]/Drafts”

    set header_cache=”~/.mutt/cache/headers”
    set message_cachedir=”~/.mutt/cache/bodies”

    If someone simple minded (like myself … ;)) just copy&pastes,
    mutt creates a ”~/-subdir in the folder it is started from.

    Christian

    Wed, 2008-07-09 at 08:40:55

  15. Argh, WordPress. What can I say. I’ll see what I can do about it, thanks for pointing it out.

    Shreevatsa

    Wed, 2008-07-09 at 09:36:53

  16. I just starting using mutt with gmail myself and I’m really impressed. I wanted to mention a couple things in case anyone stumbles onto this article:

    1.) It’s true that you don’t need to specify a ‘record’ location because Gmail will automatically save a copy of all outgoing messages that are sent via smtp.gmail.com. You should however add ‘set copy=no’ to the muttrc otherwise mutt will try to write an extra copy of sent messages to a sent folder on the local machine or it will prompt you to create a new ‘IMAP/Sent’ label within the INBOX.

    2.) Regarding the fancy quotes, you don’t even need quotes around assignments in muttrc unless they have a space somewhere in their string.

    Thayer

    Thu, 2008-08-21 at 14:44:25

    • I find that ‘set copy=no’ still shows a default in the fcc field in the compose screen; ‘unset record’ seems to ensure nothing is shown in the fcc field and also ensures that mutt does not write outgoing messages locally.

      jim

      Thu, 2012-06-07 at 02:47:38

  17. […] file to tweak, and it works with POP and IMAP. Here’s a starter guide for setting up Gmail over IMAP with Mutt, and for the adventurous, terminal-happy OS X folks, an OS X primer. Mutt is a free download for […]

  18. nice one, thanks..

    hoyd

    Wed, 2008-09-03 at 12:34:15

  19. Thanks.

    Luca Bruno

    Sat, 2008-09-13 at 08:19:51

  20. Trying to setup on Windows. Any help would be appreciated.
    Extracted mutt-1.4.zip
    Put the mutt folder to C:\Program Files so mutt.exe binary is at C:\Program Files\mutt\bin\mutt.exe
    Installed openssl and libiconv libraries from sourceforge
    Put libcharset1.dll, libeay32.dll, libiconv.dll, libintl3.dll, libssl.dll all into C:\Program Files\mutt\bin
    (Note: libiconv.dll installs as libiconv2.dll. Rename to libiconv.dll to get it to work)
    mutt now runs ok.

    Cut and pasted your information, got the following errors
    Error in C:\Program Files\mutt/etc/Muttrc, line 8: smtp_url: unknown variable
    Error in C:\Program Files\mutt/etc/Muttrc, line 17: header_cache: unknown variable
    Error in C:\Program Files\mutt/etc/Muttrc, line 18: message_cachedir: unknown variable

    Tried to rename the unix paths to be windows friendly path, but still get same errors.

    Any ideas ? would love to get this up and running (for use on my work Windows system, so installing Linux is not possible. or cygwin also unfortunately. if there’s a mutt binary for Win32, should be doable to get this running right ?). thanks :)

    You need to install mutt with –enable-smtp and with the IMAP headercache option on as well.

    Roy

    Fri, 2008-09-19 at 18:16:31

  21. […] Recent public urls tagged “imap” → peter keane: Using Gmail with mutt, the minimal way (IMAP update) «… […]

  22. Thanks! This worked great. I’m running mutt through ‘screen’ on my Ubuntu Hardy server at home, and now I can get to my GMail!

    Windsor Schmidt

    Wed, 2008-10-01 at 17:21:21

  23. I’m doing the same as Windsor Schmidt as I’ve had to move back to Windows at work, and we use Goldmine (?!?!) for email and I have claws set up on my own Ubuntu PC.

    The guide works a charm, thanks!

    Tane Piper

    Mon, 2008-10-06 at 10:31:00

  24. […] move my archive folders by that method, and wired up mutt on andrew to IMAP on gmail more or less along these lines, with some context filled in from the mutt project’s IMAP notes. Saving from one folder to […]

  25. Nice; super-easy and accurate instructions. Thanks!

    SeanG

    Fri, 2009-03-13 at 17:39:40

  26. Thanks bro your tutorial rocks… It helped me add some extra features to my final year project..

    Shishir M K

    Sat, 2009-03-14 at 18:02:50

  27. Worked great! Thanks!
    sri

    Sri Ramkrishna

    Sat, 2009-04-11 at 04:54:01

  28. @Everyone: You’re welcome!

    Shreevatsa

    Sat, 2009-04-11 at 04:54:58

  29. I’ve used some of your instructions for setting up gmail with imap. I noticed the 4/11 post so I thought I would add some things that seem useful at the moment.

    Archive:

    folder-hook . ‘macro index A “=””[Gmail]/All “‘

    folder-hook . ‘macro pager A “=””[Gmail]/All “‘

    Shift-A sends to the All Mail folder. Interestingly enough the “Mail” part of “All Mail” has to be left off for this to work for me.

    Send messages to trash (noisy):

    folder-hook . ‘macro index d “=””[Gmail]/Trash”‘

    In the trash folder a ctrl-d and a $ will expunge from there. It is easier to forget the trash folder all-together and ctrl-d the messages and finally expunge with $

    I hope this helps some people, or maybe there is a better way for all of this.

    MatthewK

    Sat, 2009-04-18 at 22:55:28

    • hmm, the save-message and enter tags were removed from the post above. Drop me an email if you want them for yourself or to post. Googling the proper format for macros will give everyone else the needed info.

      save-message and enter are needed for all of the above to work

      MatthewK

      Sat, 2009-04-18 at 23:01:10

      • Yeah, WordPress silently strips things between angle brackets thinking they are HTML tags it doesn’t recognise… very annoying. You type ampersand-l-t to enter the angle brackets: < and >.

        Shreevatsa

        Sun, 2009-04-19 at 09:23:29

  30. Hi there

    I have been trying to get mutt working with IMAP.
    I have run the run the configure script with the the IMAP, SSL, and header_cache install option.

    However, I keep getting an error which says I require Tokyo Cabinet, gmdb, or Berkley Database 4.

    I have installed each of these programs, but I am still getting this error.

    the error occurs on the line:

    checking Berkley > 4.0

    This error only happens when I try to enable header_cache

    Any help would we be great, as I have to wait for 2 mins for the headers to download each time!

    Duckshot

    Mon, 2009-08-10 at 02:37:32

  31. Thanks! It worked great. Just one thing still bothers me: I can’t cancel sending an email while it’s still sending.

    I mean, if it’s a big attachment, and I change my mind before it’s done, I can’t hit “q” to cancel. I have to wait.

    Also, I would like that mutt sent the e-mails in background. At this moment, I have to wait until the e-mail is sent to do anything else. I found a sendmail_timeout (or something like this) in Mutt’s manual but it seems like that it don’t works with Mutt’s built-in SMTP.

    Do you know how to fix it?

    Thanks,
    Vítor.

    Vítor Baptista

    Wed, 2009-08-12 at 15:39:44

    • That’s an issue with mutt in general; better to ask on the mutt mailing list.

      Shreevatsa

      Wed, 2009-08-12 at 16:51:20

  32. What is the difference btw imap_pass and smtp_pass?

    Heo

    Thu, 2009-08-27 at 10:28:04

    • Solved, I had mistyped my username.

      Heo

      Fri, 2009-08-28 at 01:21:02

  33. Removed imap_pass and smtp_pass for additional security (I.E. not leaving your PW in a plaintext file).

    mutt will automatically prompt you for your pw.

    Tony

    Sun, 2009-10-18 at 20:24:06

    • Yes, I know — see the first two sentences after the .muttrc. Glad to know it worked for you!

      Shreevatsa

      Sun, 2009-10-18 at 20:42:42

    • Which is more likely – that someone will break into your server and look at this file, or that someone will watch you typing your password over your shoulder?

      Baz

      Fri, 2013-01-25 at 01:48:13

  34. any tips for getting this to work with google apps for domains?

    what would i use for smtp if im using my own domain with gmail?

    using gmail or my domain does not work

    clk

    Fri, 2010-01-08 at 21:01:52

  35. Great tutorial…mutt is in the middle of fetching all (4000) message headers. Is it possible to set mutt to only get the X latest messages?

    majestrooo

    Wed, 2010-02-24 at 08:44:21

    • set smtp_url = “smtp://user@domain.com@smtp.gmail.com:587/”

      David Rivers

      Fri, 2010-04-02 at 01:18:53

      • That did not work sadly :(

        I’d try “smtp://{user@domain.com}@smtp.gmail.com:587/” and many things like that, never find how to configure Mutt with domain on gmail.

        boulate2boulate

        Tue, 2014-06-03 at 18:18:26

  36. Thanks so much for this. It worked like a charm! Note to users of hosted gmail, your smtp_url line will be something like:

    set smtp_url = “smtp://user@domain.com@smtp.gmail.com:587/”

    David Rivers

    Fri, 2010-04-02 at 01:17:41

    • That did not work sadly :(

      I’d try “smtp://{user@domain.com}@smtp.gmail.com:587/” and many things like that, never find how to configure Mutt with domain on gmail.

      boulate2boulate

      Tue, 2014-06-03 at 18:21:07

  37. Thanks! Worked brilliantly!

    Pravin Paratey

    Thu, 2010-04-15 at 08:08:54

  38. I’d just like to say that I looked at the mutt official documentation and was nearly scared off mutt entirely. And then I accidentally clicked your link and had it running great in seconds. So, Thanks ;)

    (one thing, on my crunchbang box with a stupid number of gmail folders, something in your “didn’t include these to justify the minimal” section makes mutt run horrendously slowly. Haven’t isolated which one it is yet, though. Just as an fyi.)

    mediapathic

    Mon, 2010-08-16 at 05:47:08

    • Glad to have helped. :-)

      What’s slow… it’s probably the “set imap_check_subscribed”, which checks all imap folders when mutt is running and notifies if there’s anything new, even if you didn’t ask it to. If you have too many folders, that is probably the slow one.

      Note from http://mutt.sourceforge.net/imap/ :

      * Mutt will scan for new mail in all of your mailboxes every mail_check seconds. The default is 5 seconds, which will make mutt feel very sluggish if you have more than a couple of mailboxes defined. You’ll like mutt better if you increase this to at least 60.
      * Mutt checks for mail in the current IMAP mailbox no more ofter than timeout seconds. The default is 600, which means you will only get notified about new mail in your current mailbox every 10 minutes. You may wish to lower this to something like 15.

      S

      Mon, 2010-08-16 at 17:51:40

      • Excellent, that’s a great place to start! Thanks for the feedback (which I am only now reading because it got sent to my spam folder, natch. Not mutt’s fault this time ;)

        mediapathic

        Sun, 2010-09-05 at 06:31:47

  39. thank you!
    finally a concise instruction!
    much appriciated!

    zoo

    Sun, 2010-09-05 at 05:46:00

  40. Also, consider adding:
    set imap_delim_chars=/

    in the muttrc if you “namespace” out your labels like me with a “.”

    e.g. my lists are named “lists.xxx” to keep them all together. Mutt barfs on this as it considers “.” as a folder separator. The above workaround is mentioned in the mutt bug tracker at http://dev.mutt.org/trac/ticket/3242

    Sandip Bhattacharya

    Sat, 2010-09-11 at 18:03:10

  41. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  42. […] tried following the instructions here and here. Currently, I can read email from my GMail account, but not send—this is on a personal computer, […]

  43. […] set sort = ‘threads’ set sort_aux = ‘last-date-received’ set imap_check_subscribed https://shreevatsa.wordpress.com/2007/07/31/using-gmail-with-mutt-the-minimal-way/ […]

  44. Reblogged this on Veronica's miscellaney and commented:
    This is how to check gmail from the terminal! This is very handy for me.

    veromarybrrr

    Fri, 2012-04-27 at 09:00:32

  45. Nice document. Thanks for sharing!

    Gordon

    Mon, 2013-09-09 at 02:28:49

  46. Thank you very much!

    Sarckz (@Sarckz)

    Fri, 2013-09-13 at 13:12:50

  47. […] Configure smtp for mutt (place the configuration under /root): […]

  48. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  49. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  50. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  51. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  52. Thanks for the guide..but Mutt only works if your Gmail account does not have two-factor authentication enabled otherwise it wont log you in. And also you have to “allow less secure apps” before Mutt can access Gmail. Thanks

    Goran

    Sat, 2017-05-20 at 11:46:48

    • Thanks. I expect things have changed in the decade since I wrote this post, but I haven’t used it myself recently so I wasn’t keeping track. I’ll look into editing this post at some point.

      S

      Sat, 2017-05-20 at 23:33:55

  53. […] Configure smtp for mutt (place the configuration under /root): […]

  54. […] solo quieres algo que puedas ejecutar en una terminal, te sugiero chucho, o […]

  55. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]

  56. […] .muttrc file looks something like this one or see below a glimpse. I am hesitant with the password. How should I store my password to use it […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: