Skip to content

Complete gmail configuration

tukusejssirs edited this page May 22, 2016 · 16 revisions

Getting the sup mail client to work with GMail/Google Apps (IMAP+SMTP).

Setup overview:

We'll be using Offlineimap - a tool to mirror IMAP mail in many formats - to store our email in the Maildir format. We'll then set up msmtp - a tool to send email through SMTP - to use GMail's system to send messages.

This tutorial is tested on Archlinux as of 2013-05-13. It should work suitably well on most other distributions.

Install offlineimap & msmtp

Sup doesn't transfer mail in or out of your machine. You'll need to install these packages:

$ pacman -S offlineimap msmtp sqlite

Note: If you're not familiar with pacman command, look Pacman Rosetta for the equivalent on your system. But the package names may vary.

Configuring offlineImap

Create a ~/.offlineimaprc and configure it based on the following annotated minimal config:

[general]
accounts = personal
ui = ttyui

[Account personal]
localrepository = personal-local
remoterepository = personal-remote
status_backend = sqlite

[Repository personal-local]
type = Maildir
localfolders = ~/mail/personal
# Spaces in pathname are bad. Lets use `archive` which is a simple word
# Besides, we only need `All Mail` folder. 
# Sup would manage mails on its own.
# If your GMail language setting is not English, you can execute 
# `offlineimap --info` to find out the name of folder which is 
# translated and encoded after your account is configured.
nametrans = lambda folder: {'archive': '[Gmail]/All Mail',
                            }.get(folder, folder)

[Repository personal-remote]
# IMAP with hardcoded GMail config
type = Gmail
# The path of ca-certfile might be different on your system.
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
# Remember that GMail requires full mail address as username
remoteuser = [email protected] 
remotepass = password
nametrans = lambda folder: {'[Gmail]/All Mail': 'archive',
                            }.get(folder, folder)
folderfilter = lambda folder: folder == '[Gmail]/All Mail'
# Or, if you have a lot of mail and don't want to wait for a long time before
# using sup, you can archive all your old mails on Gmail and only sync the
# inbox with the following line replacing the previous `folderfilter` line:
# folderfilter = lambda folder: folder == 'INBOX'

After replacing mail account and password with your own, try running:

$ offlineimap

Oh, if you haven't installed sup yet, you may do it now by following Home#Installation while leaving offlineimap working hard to download all your mails.

See the Offlineimap page for more suggestions and details.

Now that you're back, let's continue:

Add maildir source to sup

Now you can go read the New User Guide to get a sense of how sup looks like. Keep reading until you hit running sup-config, which is a wizard to get you started.

In the process of sup-config, when asked to add a source, choose "maildir" and enter ~/mail/personal/archive. Or ~/mail/personal/INBOX if you choosed so.

Note: as of sup 0.13.0, ~ sign won't be expanded. This will be fixed in 0.13.1. Please enter full absolute path at this moment.

After you're done with sup-config, you can start sup to see all your mails!

Fetching mails

Create a file at ~/.sup/hooks/before-poll.rb with the following Ruby code:

say "Running offlineimap..."
system "offlineimap", "-o", "-u", "quiet"

Now sup will launch offlineimap everytime you poll for email. Including:

  • When sup starts
  • When sup polls by the poll_interval config value
  • When you ask sup to poll for mails instantly

Configuring msmtp

Create a ~/.msmtprc, it should look something like this (again, fill in your own email account and password):

defaults
auth on
tls on
# Same as sslcacertfile in ~/.offlineimaprc
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account personal
host smtp.gmail.com
user [email protected]
# The value of `from` is only used when you're not using sup.
# But it is necessary if you're testing things out.
from [email protected] 
password password
port 587

account default : personal

Note: If you're feeling uncomfortable storing cleartext password on disk, don't worry for now. We'll come back to handle this later.

Besides, you need to run chmod 600 ~/.msmtprc to make the file only readable to your user.

Now you can test if msmtp works correctly by sending yourself a mail:

$ echo Wheee! | msmtp [email protected]

Configuring Sup to use msmtp

In ~/.sup/config.yaml, for each account, search for sendmail and modify the lines you've found to make them like this:

:sendmail: msmtp -t --read-envelope-from

So finally your account config looks like:

:accounts:
  :default:
    :signature: /home/user/.signature
    :email: [email protected]
    :name: Your Name
    :sendmail: msmtp -t --read-envelope-from

Now sup should be able to send mails using msmtp. Press c in sup to compose a mail to yourself to test it out.

Further reading

By now you've successfully configured most of offlineimap, msmtp and sup. And here're some more to read to make your mailing experience even better:

Enable 2-way syncing of flags

It is recommended that you follow the instructions on Using sup with other clients to enable 2-way syncing between sup and Gmail.

Clone this wiki locally