# Mutt + GMail + GMail

## NotQuiteSane

I'm trying to set up mutt to use multiple gmail accounts.  

I already use it for my personal account, wanted to add mybusiness account.  orginal .muttrc is backed up, and i'm trying to follow this guide.  my .muttrc can be seen here.  When i run mutt, it scrolls maybe 6 lines of 'unset: unknown variable', asks for my gpg passphrase, then another set of 6 'unset: unknown variable' then opens mutt.  Mutt says it has no mailbox, and won't respond to any key, i'm forced to use 'pkill mutt' to close it.  

I googled, and found this, but the solution suggested just bypasses the first account and then asks for the password for "user2@gmail.com".  do I need to change user{1,2} to the actual account names, and do I need to do anything else to the .muttrc at this time (improvements are planed once I have a working base .muttrc to fall back on)?

NQS

----------

## ppurka

I am contemplating moving from Thunderbird to mutt because of a 100% CPU bug in Thunderbird that has been around for a year. I bookmarked some links to help me in my migration. Maybe it will help you solve your problem too:

http://askubuntu.com/questions/196268/migrate-from-thunderbird-to-mutt (look at the main reply and the links therein)

http://www.burocrata.org/newwiki/MuttRc (setting up multiple accounts)

https://forums.gentoo.org/viewtopic-t-945868.html [KMail to mutt with Maildir and procmail] (not quite what we want, but informative nonetheless)

----------

## khayyam

NotQuiteSane ...

The 'unknown variable' errors sound to me as though you don't have the requisite useflags set for imap, sasl, and smtp, you probably want the following:

/etc/portage/package.use

```
mail-client/mutt crypt imap sasl smime smtp gpg
```

That said, I have a similar setup but use net-mail/offlineimap rather than mutt for sync'ing mail, and managing various accounts. I also use postfix which does relay dependent on the sender, the reason being that I can sync between various machines, and additionally answer mail when effectively offline (postfix queing the mail and flushing the que when net becomes available).

A brief look over your muttrc suggests that all you need do is add support for imap, sasl and smtp ... but if you want further details on how things are configured here then ask.

best ... khay

----------

## ppurka

 *khayyam wrote:*   

> That said, I have a similar setup but use net-mail/offlineimap rather than mutt for sync'ing mail, and managing various accounts.

 Can you post your offlineimap configuration, after stripping out your private information? I am also interested in using offlineimap to backup my emails locally (multiple gmail accounts <-> local backup).

----------

## khayyam

 *ppurka wrote:*   

> Can you post your offlineimap configuration, after stripping out your private information? I am also interested in using offlineimap to backup my emails locally (multiple gmail accounts <-> local backup).

 

ppurka ... sure, here is an example with two accounts one of which is gmail (all private data removed to protect the innocent ;). Note that with the gmail account some trickery is done to only sync selective directories, and to translate the names, so you may need to edit these to suite your needs. The ~/.offlineimap/pass.* files have nothing but the passphrase (no quotes or fancy business).

If you just want a one off sync, and not have offlineimap in retreaval mode then comment out 'autorefresh' and 'quick' in the 'Account' stanza's. Also, the 'Accounts' could be split into seperate files and so called at different times or what have you.

Ask, you have further question ... though maybe an idea to start a seperate thread so as not to intrude on this one.

HTH & best ... khay

----------

## ppurka

Thanks a lot khayyam! Sorry for intruding in this thread, but I think offlineimap + dovecot + any email client could be a possible configuration.

Currently I have tried out

thunderbird (100% CPU bug, and slow),

claws-mail (ugly and very confusing interface),

evolution (do the evolution devs themselves use that? It crashes left and right),

kmail (gave up on this long ago - tons of bugs; also, I can not trust this one to keep my emails safe),

alpine (very slow over imap; even slower with multiple accounts),

trojita (not featureful enough; very nascent and restricted interface but very fast),

opera mail (not featureful enough; otherwise quite nice).

So, now I am looking at mutt, as well as offlineimap. The configuration of both is daunting, as soon as multiple email accounts need to be handled.

----------

## NotQuiteSane

 *khayyam wrote:*   

> A brief look over your muttrc suggests that all you need do is add support for imap, sasl and smtp ... but if you want further details on how things are configured here then ask.
> 
> best ... khay

 

I have the following:

```
[ebuild   R    ] mail-client/mutt-1.5.21-r12::gentoo [1.5.21-r12::my_local_overlay] USE="berkdb crypt gdbm gpg imap nls sasl smime smtp ssl -debug -doc -gnutls -idn -mbox -nntp -pop -qdbm (-selinux) -sidebar -tokyocabinet" 0 kB
```

package.use shows:

```
mail-client/mutt gpg imap sasl smime smtp
```

so i guess i can try offlineimap, i did look at it before.

At one time I had 6 addresess all imported into one via POP plus my business account. Had postfix, fetchmail and procmail all set up.

Then I got a gmail account, and an android phone and found I liked IMAP, plus contracting jobs increased over my own domain (go figure).  but i'm "old-school", grew up on the command line, and if I can get rid of anything GUI, good.

Still, if I could get these two to work, i'd be happy for now.  I can always improve on the setup later, once it is working

NQS

----------

## khayyam

 *NotQuiteSane wrote:*   

> 
> 
> ```
> [ebuild   R    ] mail-client/mutt-1.5.21-r12::gentoo [1.5.21-r12::my_local_overlay] USE="berkdb crypt gdbm gpg imap nls sasl smime smtp ssl -debug -doc -gnutls -idn -mbox -nntp -pop -qdbm (-selinux) -sidebar -tokyocabinet" 0 kB
> ```
> ...

 

NotQuiteSane ... the useflags looks fine.

I think I see the source of the error, you have: account-hook . 'unset imap_user unset imap_pass', try:

```
account-hook . 'unset imap_user'

account-hook . 'unset imap_pass'
```

... also, you 'set folder', 'mailboxes=' for one account and then further down do the exact same for the second account, the second of these will be the one applied as there is no context for the settings ... so some other method is needed. The method I use is the following (but note my offlineimap is configured so that directories that exist for each account have the identical schema).

```
send-hook "(~t @)" 'set record="+Sent"'

send-hook "(~f @foo.org)"  'my_hdr From: Foo A. Bar <fooabar@foo.org> ; \

                                my_hdr Reply-To: Foo A. Bar <fooabar@foo.org>'

send-hook "(~f @gmail.com)"  'my_hdr From: Foo A. Bar <fooabar@gmail.com> ; \

                                my_hdr Reply-To: Foo A. Bar <fooabar@gmail.com>'

folder-hook ~/mail/foo-local/INBOX 'set folder="~/mail/foo-local"'

folder-hook ~/mail/gmail-local/INBOX 'set folder="~/mail/gmail-local"'

folder-hook . 'set postponed="+Drafts"'
```

So, it is by switching between the folders which trigger the '+Sent', '+Drafts', folder, name, and reply_to for the respective accounts.

For mailboxes you don't need to supply +Sent, etc, as this is only for the mailboxes mutt scans for new mail, you can simply have one definition as mutt doesn't need to associate them with an account:

```
mailboxes = +foo-local/INBOX +gmail-local/INBOX
```

With the above folder-hooks mutt needs to be provided with a default account so that at start it knows which mailbox to open, so define the most used account like so:

```
set folder="~/mail"

set spoolfile=+foo-local/INBOX

set hostname="foo.org"

alternates "fooabar@(gmail.com|foo.org)|(foo.bar@work.com)"
```

The above is obviously designed with local mailboxes in mind, but you should be able adapt it for remote imap should you want to go that route (though again, because of the non-standard naming google uses the above hooks will not work ... its a PITA to not have the, mostly, consistant names used in imap).

 *NotQuiteSane wrote:*   

> so i guess i can try offlineimap, i did look at it before.

 

The main advantage is being able to sync multiple machines, and or access the mail via some other method and still have them all sync up. Plus, if your using a laptop you can answer your email without needing to be online .... as long as you have some local mailserver (I used postfix) which can defer_transport.

I'm more than happy to post further configs (postfix, mutt, etc) just ask.

best ... khay

----------

## NotQuiteSane

Well...

I messed up somewhere.  I replaces all the user1 and user2 with actual settings, and put in the suggested folder hooks.  see http://bpaste.net/show/94008/

But now I put in my pass phrase and get:

```
/home/nqs/.mutt/notquitesane/INBOX: No such file or directory (errno = 2)
```

Also the macros seem unbound.

Also, i'm unsure if this is set for .maildir or .mbox.  I want the former.

NQS

----------

## khayyam

 *NotQuiteSane wrote:*   

> 
> 
> ```
> /home/nqs/.mutt/notquitesane/INBOX: No such file or directory (errno = 2)
> ```
> ...

 

NotQuiteSane ... your setting the folder to ~/.mutt when it should be something like ~/mail, ~/Mail or imap: ... ~/.mutt is where mutt config files, or what-have-you, are stored. The 'folder' is the root of the directory where the mail is delivered to with the 'spoolfile' being relative ("+") to that dir. 

 *NotQuiteSane wrote:*   

> Also the macros seem unbound.

 

The config file will not work as is ... because 'set foo' sets foo=value ... if its defined again further on then the value is set to something else. Also, as your using imap then the folder and spoolfile need to reflect this fact.

```
set hostname="gmail.com"

set imap_user="notquitesane@gmail.com"

set imap_pass=""

set folder="imaps://imap.gmail.com"

set spoolfile=+INBOX

set postponed=+[Gmail]/Drafts

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

set smtp_url="smtp://notquitesane@smtp.gmail.com:587"

set smtp_pass=""

set certificate_file=~/.mutt/certificates

set ssl_force_tls=yes

set ssl_use_sslv3=yes
```

The spoolfile, record, and postponed are relative ("+") to the folder= ... in the above that would be the remote imap://

 *NotQuiteSane wrote:*   

> Also, i'm unsure if this is set for .maildir or .mbox.  I want the former.

 

Its neither, its imap ... at least in your case.

best ... khay

----------

## NotQuiteSane

 *khayyam wrote:*   

> NotQuiteSane ... your setting the folder to ~/.mutt when it should be something like ~/mail, ~/Mail or imap: ... ~/.mutt is where mutt config files, or what-have-you, are stored. The 'folder' is the root of the directory where the mail is delivered to with the 'spoolfile' being relative ("+") to that dir. 

 

Ok, i've set it to ~/.mail

 *khayyam wrote:*   

>  *NotQuiteSane wrote:*   Also the macros seem unbound. 
> 
> The config file will not work as is ... because 'set foo' sets foo=value ... if its defined again further on then the value is set to something else. Also, as your using imap then the folder and spoolfile need to reflect this fact.

 

Alright, i'll have to fix those dupes

 *khayyam wrote:*   

>  *NotQuiteSane wrote:*   Also, i'm unsure if this is set for .maildir or .mbox.  I want the former. 
> 
> Its neither, its imap ... at least in your case.

 

as long as it's not mbox, i'm happy.

Didn't have time to work on it until today.  i'd been using 'mutt -F .muttrc.bak'

Using that and the code you posted last message I created .muttrc.  it worked (both files actually have passwords in them, log right in)

I got to thinking about passwords, so i decrypted .passwords.

it looks like 

```
GMail1     `1234aoeuhtns-

GMail2     \=/l][09;qjk
```

(not actual passwords)

so I re-created it to show

```
GMail1     "`1234aoeuhtns-"

GMail2     "\=/l][09;qjk"
```

and shifted comments around to get this .muttrc

which fails.  it's probably something simple, but i'm going to step back and lookat it again later

NQS

----------

## khayyam

 *NotQuiteSane wrote:*   

> i've set it to ~/.mail

 

NotQuiteSane ... if you plan on using the imap method then this needs to be set to the remote mailbox. As I said its the top level of where ever mail is delivered.

 *NotQuiteSane wrote:*   

>  *khayyam wrote:*   The config file will not work as is ... because 'set foo' sets foo=value ... if its defined again further on then the value is set to something else.[...] 
> 
> Alright, i'll have to fix those dupes

 

basically the various settings for seperate mail accounts need to be triggered by some change, ie a 'hook' ... thats what the folder-hooks above do, when switching between folder a and folder b the various set=foo come into effect. You could probably use the same hook but set the folder to the URI of the INBOX ... I imagine you should then be able to add these same URI to 'mailboxes=' and be able to switch with 'c' (change mailbox). 

 *NotQuiteSane wrote:*   

> Using that and the code you posted last message [...]  it worked (both files actually have passwords in them, log right in).

 

OK, good, so all you need do is add some hooks that will change the configuration based on some event.

 *NotQuiteSane wrote:*   

> I got to thinking about passwords, so i decrypted .passwords. [....] which fails.  it's probably something simple, but i'm going to step back and lookat it again later.

 

Honestly, why not do this:

~/.muttrc

```
source ~/.mutt/pass
```

and ...

```
cat ~/.mutt/pass

imap_pass="foo"
```

You can use some form of encryption, but have it done as part of your login. You still need to provide hooks for doing this but it may be a lot easier to handle. 

best ... khay

----------

