Take Control of your Email with Mutt, OfflineIMAP and Notmuch

mutt-1I’ve been an avid user of the Mutt email client for quite some time, preferring it to GUI clients or web for its speed, hotkey-everything approach, and integration with vim that compliment my daily workflow.  Still, I found search functionality lacking compared to Thunderbird or other GUI clients.  Mutt has built-in, powerful regex search but I sought something more intuitive – I could never remember the arcane syntax for it to be timely but I didn’t want to bother with a cumbersome GUI for searching and indexing.  Here is how I combined Mutt, OfflineIMAP and Notmuch into a powerful email/search system to take back my inbox.

 

Update: 2017-07-17 – Gmail users consult this post for Offlineimap configuration then return to step 3a below.

Update: 2016-08-08 – I’ve switched from mutt to neomutt, it’s pretty much the same just more maintained and improved.  Every here will work there and vice-versa.

A few years ago a co-worker introduced me to a blog post that explained how a marriage of Mutt and the exhaustive indexing and searching functionality of notmuch could give me what I was lacking.  I’ve found tremendous gains in productivity, speed and efficiency with this setup.  I get a ridiculous amount of email through open source project mailing lists, team and company mailing lists and other sources and it’s basically the only way I can keep up.

It’s not for everyone, but if you find that using keyboard hotkeys over kludgy mouse clicks is preferable but you’ve always avoided a console email client like Mutt, Alpine or Elm because of lacking search/indexing functionality then you may find it useful.  If you find yourself using Thunderbird or another GUI client just for the search functionality this might be useful.

Another benefit is that using a console email and a console IRC client (I like weechat) I can do 100% of my work in a screen session, basically being able to work without a laptop in a pinch and only a terminal.  While that may not mean much to most people it makes me feel more like Caine from Kung-Fu.

Please note that you must be running a recent Linux distribution due to the libraries required.  This should also work on any operating system where mutt runs natively (FreeBSD, OSX, etc).

The Goldberg Machine of Awesome: List of Components.

1) Mutt (with sidepane patch)
The Mutt MUA (mail user agent) was created by Pilgrims on the voyage of the Mayflower to the Americas, though the concept of e-mail, internet and correspondence outside of pidgeons and quill pens upon parchment had not yet been invented.
One can use the Mutt MUA without the sidepane patch, but I find it extremely useful .. especially if you have lots of IMAP folders to manage like me.  Mutt is very good at handling messages with multiple threads and mailing lists, it is also extremely fast to use – it is keyboard/console only with more customization and configuration options than you’d ever want.

Below you’ll see the sidepane and a common business email compose window

mutt-sidepane1mutt-compose

2) OfflineIMAP
OfflineIMAP is like a grocery store delivery service – it keeps your fridge stocked with food without you having do anything.  OfflineIMAP fetches mail on set intervals from IMAP and keeps it on your local filesystem.  This has two major benefits:

  • offline email composition and reading, syncs remotely when its run
  • sets up an easy way for local indexing and search

It’s been noted that you can replace OfflineIMAP with mbsync/isync or any similiar IMAP sync program if this works better for you.  This is a modular setup so you can pick other components to use if you like (some people prefer emacs to vim for example).  I’ve never had issues with OfflineIMAP but you’ve got other choices if you wish.

3) Notmuch
Notmuch is an email indexing/tagging application that basically gives you your own Google Search appliance for your email.  It can find pretty much anything except for Jimmy Hoffa.  With the “mutt-notmuch” script you can plug this functionality into Mutt via a configurable hotkey  (I use F8).  Below you can see a common search.

mutt-search

4) Mutt-Notmuch Script
(Perl)
Useful things in life like electricity, plutonium and velcro are created with Perl, mutt-notmuch is no different.  This useful script was introduced to me by a useful blog post that basically echoes the exact type of usage I’m explaining here.  You define mutt-notmuch execution as a hotkey inside your .muttrc and call it to search mail after the initial setup.

Putting it all together – How to set things up

Note: I’ve switched to neomutt, updated below.  neomutt is a well-maintained fork of mutt that contains lots of newer patches and functionality that’s not in upstream mutt yet, and it’s also extremely well-documented.  Highly recommended!

1a) Install mutt or neomutt (sidepane patch optional but encouraged)
If you opt to use the sidepane patch you’ll need to compile your own mutt from source unless you use Karel Zak’s mutt-kz fork neomutt which includes everything.  If you use an RPM-based Linux distribution it’s easier to just use any number of Fedora COPR Repos.  I am focusing on Fedora 23+ here.

dnf copr enable flatcap/neomutt
dnf install neomutt

1b) Configure Mutt:  .muttrc
Mutt is a very flexible, configurable MUA – perhaps the most configurable in existence.  Like the magical .vimrc, the .muttrc file can turn into a work of art as there are near-unlimited levels of customization and complexity one can harness.  If you are not already a mutt user and have one I’d recommend borrowing heavily from someone else.  The default one is fine for your distribution is fine too and you can build on it as needed later.

I originally borrowed mine from ashcrow and modified it heavily – you can find my sanitized .muttrc here for reference.  The default .muttrc is well commented and you can start with that but there are just a few variables you’ll need for bare-bones operation with notmuch and offlineimap.

There are two important variables below, setting your mailbox format to “maildir” and the necessary settings for including the mutt-notmuch script and binding to a hotkey. Your paths may vary.   I also have example mailcap (associate opening attachments with external programs) and mutt-gpg config files here.

— snip  .muttrc —

### save and sync my sent messages
set record=~/Maildir/Sent
## GMAIL USERS USE Sent Mail below instead:
## set record="~/Maildir/Sent Mail"
set spoolfile=~/Maildir/INBOX
# set header cache
set header_cache=~/Localmail/hcache
# needed for maildir format
set mbox_type=Maildir
set folder=~/Maildir/
# IMAP and INBOX (this should map to any existing IMAP folders)
mailboxes =INBOX \
=Sent \
=Drafts \
=Junk \
=Trash \
=Lastfolder
### BEGIN NOTMUCH-MUTT SETTINGS
    macro index  \
          "unset wait_key~/.mutt/mutt-notmuch.pl --prompt search~/.cache/mutt_results" \
          "search mail (using notmuch)"
    macro index  \
          "unset wait_key~/.mutt/mutt-notmuch.pl thread~/.cache/mutt_resultsset wait_key" \
          "search and reconstruct owning thread (using notmuch)"

— snip .muttrc —

2a) Install OfflineIMAP
Most distributions like Fedora carry OfflineIMAP, make sure you install it.

dnf install offlineimap

GMAIL USERS READ THIS INSTEAD then return to 3a

2b) Configure OfflineIMAP (non Gmail): .offlineimaprc
Next, you need an offlineimaprc file.  I place this in ~/.offlineimaprc and it looks like this:

[general]
accounts = ExampleOrg

[Account ExampleOrg]
localrepository = ExampleLocal
remoterepository = ExampleRemote
status_backend = sqlite
postsynchook = notmuch new

[Repository ExampleRemote]
type = IMAP
remotehost = mail.example.com
remoteuser = you
# probably a bad idea
remotepass = ***********
ssl = yes

[Repository ExampleLocal]
type = Maildir
localfolders = ~/Maildir
restoreatime = no

Note: There are two methods to do this, GSSAPI and SSL/password.  I would not recommend the SSL/password approach if you use a system.  The only benefit of using the SSL/password in the config is so that you can continually sync mail without a kerberos ticket (though you can also specify a longer duration for ticket expiration).  This goes without saying to use proper u-g-o permissions on those types of files.

2c) Sync OfflineIMAP
Once your OfflineIMAP configuration is in place it’s time to run the first sync.  This may take a substantial amount of time depending on how many mail messages/folders you have.  With 1.3million+ emails my sync took around 12hours.

time offlineimap

3a)  Install notmuch
The next step is straightforward, simply install notmuch.

 dnf install notmuch

This will pull in all types of Perl dependencies but that’s ok.

I believe the following packages are pulled in as a result of “perl-Email-Sender perl-MailTools”

dnf install perl-Email-Sender perl-MailTools perl-Mail-Box

3b) Configure notmuch

notmuch setup

Follow the prompts, pointing it to your Maildir you set (and synced with OfflineIMAP)

3c) Index your maildir with notmuch

notmuch new

4) Download mutt-notmuch
Pull down mutt-notmuch from here.  The man page can be found here or in HTML format here.
Place this where you refer to it in your .muttrc above.

5a) Option #1: Set up cron to sync OfflineIMAP

  • notmuch is called as a post hook from your offlineimaprc if you used my example above

NOTE: some people have issues with offlineimap hanging, simply prepend “killall offlineimap ; ” to the cron line below as a work-around but a cleaner way is to use a script so you don’t generate crond email and things only sync when you are online.

# sync IMAP store every 8min for offline use
*/8 * * * * offlineimap -q -u quiet

5a) Option #2: Setup a script to only sync while online (or when mailserver is available)

I use the following script in my crontab in lieu of the sync cron above to run on my laptop.  If you can ping your IMAP server it will pull mail down.

#!/bin/bash
# sync offlineimap if you have connection to the internet
# and you can ping your imap server successfully.

imapserver=$(cat ~/.offlineimaprc | grep remotehost | awk '{print $3}')
imapactive=$(ps -ef | grep '[o]fflineimap' | wc -l)
netactive=$(ping -c3 $imapserver >/dev/null 2>&1 && echo up || echo down)
mailsync="/usr/bin/offlineimap -u quiet -q"

# kill offlineimap if active, sometimes it hangs
case $imapactive in
'1')
 killall offlineimap && sleep 5
;;
esac

# Check that you can access the SMTP server
case $netactive in
'up')
 $mailsync
;;
'down')
 :
;;
esac

6) Tips and Hotkeys
If you’re not an avid mutt user, you might want to check out the help menu by typing ? then use vim search (default mutt editor) to find your hotkeys as defined by your .muttrc or defaults

Using Multiple Accounts
Mutt has some ways to intelligently use multiple accounts, and try to pick the best correct one when replying to email.  Rather than explain it here, please read the Mutt MultiAccount Examples here.

Make Mutt not use Highlighting in Vim
Since I use Vim as my primary text editor and for development I have a plethora of language and syntax highlighting.  This can be irritating when typing email however.  I use the following line in my ~/.vimrc to turn this off.

autocmd BufNewFile,BufRead /tmp/*mutt* set noautoindent filetype=mail wm=0 tw=78 nonumber digraph nolist nopaste

Common Sidepane and Misc Hotkeys
Here are some common hotkeys I use, configurable in your .muttrc.

  • b” shows or hides the sidepane bar
  • control + n” moves down one sidepane folder
  • control + p moves up one sidepane folder
  • control + o” opens a selected sidepane folder
  • .r” marks all messages read in an IMAP folder
  • “.i” sorts message view to all unread/flagged
  • “.a” reverts message view back to all
  • control + b” inside message opens URLView
  • v” to view attachments inside a message
  • esc + r” marks a thread read
  • esc + s” saves (copies) messages to a different folder
  • g” replies-all when in message view
  • r” replies to individual sender in message view
  • L” replies to email list in message view
  • d” marks message for delete in message list
  • D” marks messages for delete on a partial match
  • U” undeletes messages based on a partial match
  • “a” creates email alias for address based via any email in mailbox

Untagging / Removing Tags En-Masse
A really easy way to remove all tags and special flags on your emails is the following:

tag-pattern (T)
enter pattern (~F)
clear flag of tag messages (;W)
enter flag (!)

This is useful when trying to sort by read/unread via a macro as people tend to abuse message flags like important! and they get picked up.

Notmuch Syntax
Notmuch search syntax is similar to Google search.  You should read the notmuch documentation for full usage.  Here are some examples, and you can combine any manner of them together for added granularity.

  • from:will@example.com AND to:john@example.com OR to:jane@example.com
  • date:”2015-09-01″..”2015-09-02″
  • budget AND FY14 OR FY15 AND date:”2015-09-01″..”2015-09-02″

Victory!  Have control over your mail!
At this point you should have offlineIMAP running in cron and keeping your local Maildir up to date, notmuch will be indexing the crap out of it and mutt will be used locally.
For an idea of my usage, I keep around 1.8Million emails (14GB) locally, discarding automated stuff and have no problem keeping up with it all.

victorywaitsonyourfingers_sm

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , , , , , , , . Bookmark the permalink.

14 Responses to Take Control of your Email with Mutt, OfflineIMAP and Notmuch

  1. Nice!

    You can definitely enhance this approach to be more Shao Lin Monk nomad by packaging up everything you use into a few docker containers (auto-built via public github repositories) and a small cloud instance that houses your credentials and a shell-in-a-box ssh shell with a two-factor Google authenticator for login, and voila, now you have you whole setup in an always available cloud instance with all software configured in easy to spin containers.

    Liked by 1 person

    • Will Foster says:

      Hey Kayvan, this is a pretty neat idea. My only issue with this for personal usage is the ~15G+ of local mail housed somewhere (encrypted, and constantly updated over OpenVPN). For someone doing this with a more disposable, lightweight setup this might work really well – I like the transient nature of it but 2FA would be a must as you mentioned.

      Like

  2. Amanda says:
    .gist table { margin-bottom: 0; } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters [general] accounts = Velociraptor pythonfile = ~/.offlineimap/pass.py [Account Velociraptor] localrepository = VelLocal remoterepository = VelRemote # In 7.0 sqlite is the only thing supported # status_backend = sqlite postsynchook = notmuch new [Repository VelRemote] type = IMAP remotehost = mail.{redacted} cert_fingerprint = {redacted} remoteuser = amanda@{redacted} remotepasseval = get_pass("amanda") ssl = yes [Repository VelLocal] type = Maildir localfolders = ~/Maildir restoreatime = no view raw .offlineimaprc hosted with ❤ by GitHub No joke: Thunderbird has been getting super bloated lately. Searches take forever. So I’ve been easing my way into Notmuch and mutt which is actually great. I still need to work out an address book, but this works well for me. To Do DONE: Get my password out of cleartext (using pass now) Respect non ASCII characters DONE: for a while I was running notmuch new after offlineimap but I added postsynchook = notmuch new to my offlineimap config instead. HTML Attachments To reliably open HTML in a browser, you need to add a line to mailcap: text/html; firefox %s;copiousoutput And you need to set mailcap_path = ~/.mailcap in neomuttrc While Loop
    while true; do time offlineimap && date +\"%T\"; sleep 20m; done
    
    Crontab */10 * * * * offlineimap -q -u quiet view raw README.md hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters text/html; firefox -private-window %s;copiousoutput application/ics; khal import -a logistics %s text/calendar; khal import -a logistics %s image/jpeg; shotwell %s image/jpg; shotwell %s image/gif; shotwell %s image/png; shotwell %s application/pdf; evince %s view raw mailcap hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters source ~/.config/neomutt/pass.sh| set smtp_url = "smtp://amanda@{redacted}@mail.{redacted}:587/" set smtp_pass = $my_pass set ssl_force_tls = yes set from = "amanda@{redacted}" set realname = "Amanda Hickman" set signature = "~/.config/neomutt/signature" set status_format = "%n new | %M in %f [%v]." set xterm_set_titles = yes # notmuch set nm_default_uri="notmuch:///home/amanda/Mail" # path to the maildir set spoolfile = ~/Mail/INBOX set record = ~/Mail/INBOX.Sent set postponed = ~/Mail/INBOX.Drafts set mbox_type = Maildir set folder = ~/Mail/ # notmuch bindings bind index,pager noop macro index,pager \\\\ "<vfolder-from-query>" # looks up a hand made query macro index A "<modify-labels>+archive -unread -inbox\\n" # tag as Archived macro index I "<modify-labels>-inbox -unread\\n" # removed from inbox macro index S "<modify-labels-then-hide>-inbox -unread +junk\\n" # tag as Junk mail macro index + "<modify-labels>+*\\n<sync-mailbox>" # tag as starred macro index – "<modify-labels>-*\\n<sync-mailbox>" # tag as unstarred # ctrl u searches for URLs macro pager cu |urlviewn # Remap bounce-message function to “B” bind index B bounce-message # show the year via http://www.sendmail.org/~ca/email/mutt/manual-6.html#index_format set index_format = "%4C %Z %{%b %d %Y} %-15.15L (%?l?%4l&%4c?) %s" ## Save Hooks save-hook '~s [Rr]eceipt' =INBOX.receipts save-hook '~s order confirmation' =INBOX.receipts save-hook '~s authorized a payment' =INBOX.receipts save-hook '~e Venmo' =INBOX.receipts save-hook . =INBOX.Archives.2018 ## Addressing macro pager,index a "<pipe-message>khard add-email<return>" "add the sender address to khard" set query_command= "khard email –parsable %s" bind editor <Tab> complete-query bind editor ^T complete set mailcap_path = ~/.config/mailcap set print_command="/home/amanda/.mutt/print_unicode.sh" view raw neomuttrc hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters ## no longer using this in favor of `pass.sh` #! /usr/bin/env python2 from subprocess import check_output def get_pass(account): return check_output("pass Velociraptor/" + account, shell=True).splitlines()[0] view raw pass.py hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters #! /bin/bash # Script to extract my password via pass my_pass=$(pass Velociraptor/amanda) echo set my_pass = ${my_pass} view raw pass.sh hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters #!/bin/bash ## Note: No longer using this, in favor of txt2pdf with unicode support. input="$1" pdir="$HOME/Desktop" open_pdf=evince # check to make sure that enscript and ps2pdf are both installed if ! command -v enscript >/dev/null || ! command -v ps2pdf >/dev/null; then echo "ERROR: both enscript and ps2pdf must be installed" 1>&2 exit 1 fi # create temp dir if it does not exist if [ ! -d "$pdir" ]; then mkdir -p "$pdir" 2>/dev/null if [ $? -ne 0 ]; then echo "Unable to make directory '$pdir'" 1>&2 exit 2 fi fi tmpfile="`mktemp $pdir/mutt_XXXXXXXX.pdf`" enscript –font=Courier8 $input -2r –word-wrap –encoding=88593 -p – 2>/dev/null | ps2pdf – $tmpfile $open_pdf $tmpfile >/dev/null 2>&1 & sleep 1 rm $tmpfile ## note: pulled –fancy-header=mutt from line 24 b/c I need to restore mutt.hdr for that to work. view raw print.sh hosted with ❤ by GitHub This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters #!/bin/bash ## Using https://github.com/baruchel/txt2pdf to print emails to PDF with unicode support. pdir="$HOME/Desktop" open_pdf=evince scriptloc="python3 $HOME/.config/neomutt/txt2pdf.py" # check to make sure that we're looking for txt2pdf in the right place if ! command -v python3 $scriptloc >/dev/null; then echo "Is $scriptloc installed?" exit 1 fi # create temp dir if it does not exist if [ ! -d "$pdir" ]; then mkdir -p "$pdir" 2>/dev/null if [ $? -ne 0 ]; then echo "Unable to make directory '$pdir'" 1>&2 exit 2 fi fi # dump stdin to a tempfile tmptxt="`mktemp $pdir/mutt_XXXXXXX.txt`" cat >> $tmptxt tmpfile="`mktemp $pdir/mutt_XXXXXXXX.pdf`" # Actually write the text into a PDF. $scriptloc -o $tmpfile $tmptxt $open_pdf $tmpfile >/dev/null 2>&1 & sleep 1 rm $tmpfile rm $tmptxt view raw print_unicode.sh hosted with ❤ by GitHub I’m pretty thrilled to have this working nicely but I’ve been doing a ton of tagging and I finally realized that (duh) my notmuch tags are local. I’m wondering if you’ve encountered any clever ways to sync the tags across machines? Or to carry the information? Pack it into a header and then unpack it again? I’m really only dealing with two computers here. LikeLiked by 1 person
    • Will Foster says:

      Hey Amanda, I’m glad that you’ve gotten a setup you like – looks sweet! For multiple machines I either sync them independently against the same IMAP server or if I’m setting up something new I’ll simply keep them synced with rsync. You’ve got to be careful with overwriting newer offlineimap sqlite files with older ones however, you can inadvertently push delete flags to your messages (happened to me once – was my own fault).

      Sorry, I don’t have any really clever ways of managing distributing tags inside of notmuch across computers, it might help to ask on the project github. Two small improvements I’d make is to use some logic in your sync to not try if the IMAP server is unavailable, see:

      https://github.com/sadsfae/misc-scripts/blob/master/shell/mailsync.sh

      This might help to eat less cycles on a laptop if you’re firing off the sync in cron.

      Like

  3. PJ says:

    Interesting, thanks. I use X1 (x1.com) on Windows 7 to index mail (and everything else). I’m looking to switch to a Linux alternative and notmuch wasn’t listed on the AlternativeTo site.

    Like

  4. prattfall says:

    Stupid question, because I already know the answer (e.g. “you don’t) – how do I get this lovely nonsense on my phone when I’m mobile?

    Like

    • Will Foster says:

      Stupid question, because I already know the answer (e.g. “you don’t) – how do I get this lovely nonsense on my phone when I’m mobile?

      Hey Pratfall, For mobile you’d just use a mobile mail application, the Gmail IOS/Android app is actually quite good or there’s K9 for Android or the regular IOS mail app for iPhone for regular IMAP mail. You’ll still be operating on the same set of mail, sent messages, etc when you’re on the go. I suppose if you really wanted to you could root your phone and build it all but it sounds like a lot of trouble. If you were really motivated I’m sure the Neomutt team would love to include Android builds for it and it does run on OSX so you could theoretically build it for iPhone IOS.

      Like

  5. Maha says:

    I have used your method in ubuntu and this work very well. Nevertheless, using the same code with fedora, the offlineimap recuperation of mails is very, very long (about 30s for each email); do you have any idea of what can cause the problem? I was using the same connection when using ubuntu (it was just 2 days ago).

    Thanks for your marvellous tutorial!
    Maha

    Like

    • Will Foster says:

      Hey @maha, I’m glad the guide has been helpful. I don’t have any slowdowns for mine but one change in Fedora 28 and newer versions of offlineimap is the “status_backend” directive is no longer valid, though it should be using sqlite. That’s all I can think of currently. 30 seconds is indeed way to long, are you sure it’s using sqlite as the backend and not flat files? Even then that seems like a long time. Is this the same hardware as before?

      Like

      • maha says:

        I fact, without any understandable reason for me, when I restart for the n-th time, the process was quicker… But, it is maybe because of restriction given by gmail when accessing too much data? I really don’t know (not used to use any kind of internet protocol ^^).

        So, I’ve now a complete local backup for my emails, thanks a lot : ).
        But I thought that I would be also able to sent emails with this configuration. But when I launch neomutt, there is no attempt of connexion to gmail: just the lecture of the local backup and I can’t send emails too. Is there a way to send emails also?

        I tried to past this in my .muttrc

        (https://forums.freebsd.org/threads/configuration-for-mutt-with-gmail-account.65154/ )

        set ssl_starttls=yes
        set ssl_force_tls=yes
        set imap_user = ‘
        This e-mail address is being protected from spambots. You need JavaScript enabled to view it

        set imap_pass = ‘PASSWORD’
        set from=’
        This e-mail address is being protected from spambots. You need JavaScript enabled to view it

        set realname=’Your Name’
        set folder = imaps://imap.gmail.com/
        set spoolfile = imaps://imap.gmail.com/INBOX
        set postponed=”imaps://imap.gmail.com/[Gmail]/Drafts”
        set header_cache = “~/.mutt/cache/headers”
        set message_cachedir = “~/.mutt/cache/bodies”
        set certificate_file = “~/.mutt/certificates”
        set smtp_url = ‘smtps://
        This e-mail address is being protected from spambots. You need JavaScript enabled to view it
        :
        This e-mail address is being protected from spambots. You need JavaScript enabled to view it
        :465/’
        set move = no
        set imap_keepalive = 900

        But it is very likely to be a bad idea, because I’m sure thant your method cold allow the
        sending of message.. In fact, I’ve the impression that offlineimap is connecting to gmail but not neomutt.

        I don’t know if I’m very clear, by the way; sorry for that!

        Like

      • Will Foster says:

        I think your process isn’t right, you shouldn’t have neomutt contact Gmail directly it should be pointed to a maildir format locally on your laptop. It’s offlineimap job only to contact gmail via IMAP and pull down your mail locally (and optionally notmuch indexes it for awesome search), then neomutt just looks at the local mail on disk. You can of course just not use offlineimap and access IMAP directly but you lose out on a lot of the benefits of offline email, notmuch indexing and having a physical, up-to-date copy of your mail locally.

        Here’s how the process should go:

        1) Offlineimap syncs against Gmail IMAP to local disk (you can use the API per my guide or an application password)
        2) notmuch runs as a post-hook from your ~/.offlineimaprc to index and tag any new messages
        3) Neomutt mailbox spool points to the local maildir where offlineimap syncs mail

        For example here’s my config for the sections you have, also note that I create the same IMAP folder structure underneath my INBOX inside the config:

        set postponed=/home/myusername/Maildir/Drafts
        set record="~/Maildir/Sent Mail"
        set spoolfile=~/Maildir/INBOX
        set mbox_type=Maildir
        set folder=~/Maildir/
        mailboxes =INBOX \
        =Sent\ Mail \
        =Drafts \
        =Spam \
        =Trash \
        =2007-2011-inbox

        You can see a mostly up-to-date copy of my ~/.muttrc and ~/.offlineimaprc here.

        Like

  6. maha says:

    Ok, I understand better the process, i think. But to be perfectly happy, I want to be able to send messages, for exemple in a way as this:
    1 I create a message with neomutt that is stocked in a category “to send”
    2 When offlineimap start, the message is send.
    Is this possible? I can of course create a message in “Draft” for exemple, but I have after this to connect myselft to gmail and send the message.

    But maybe this is completely not the subject because the principe is an offline mail box.
    By the way,,,,,, really see the advantages of an offline mail box except of course the fact to have the messages in local, and that is very interesting.

    Like

    • Will Foster says:

      Offlineimap doesn’t send messages, it just keeps your remote mailserver IMAP synced with the local mbox copy on disk.

      Sending should always be done via SMTP and configured via Neomutt, for example I use the following for my employers gsuite domain / Gmail and the subsequent IMAP API key (per the guide).

      set smtp_url = 'smtps://myusername@examplecompany.com@smtp.gmail.com'
      set smtp_pass = 'XXXXXXXXXXXXX'

      In Neomutt if you’re offline you can just “q” and select yes when it asks you if it wants to save it or not, this will save to where you’ve defined your drafts folder.

      What I do a lot is if I’m on a plane I’ll read email, compose a bunch of stuff, save to drafts etc. When I get online I’ll type ‘m’ to compose a new message, you’ll get a prompt to resume any drafts. Go into the ones I want to send and send. a sync to offlineimap will sync new mail plus mark what you’ve read read, what you’ve deleted deleted and copy what you’ve just now sent into “sent” on the gmail side.

      To make sure things sent from neomutt also get a copy synced via OfflineIMAP to gmail you just need something like:

      set record=~/Maildir/Sent

      Hope this helps better explain it.

      Like

Have a Squat, Leave a Reply ..

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