Elric's random thoughts in idle times

"Why stop now, when I'm just starting to hate it?" – Marvin the robot

offlineimap and msmtp

leave a comment »

Mutt. Send and receive

To be able to send and receive mail we need a MTA (mail transfer agent). You can have both features in a full MTA like exim, but again, it’s hard to configure and more feature rich than what you really need. You can use Offlineimap for retrieving, a MRA (mail retrieval agent). msmtp sends your email, but you can download the msmtp-mta package (Debian), and replace exim as MTA. It supports multiple accounts.

Let’s start by configuring offlineimap. You’ll see I have the configuration files in ~/.mutt. Since you may end up with a few mutt-related configuration files, it’s not a bad idea to put them in the same place.


It’s faster and easier to keep a local copy of your email. offlineimap fetches it and synchronizes folders between gmail and your local copy. It will also create any new folder/label and write the name in muttrc.mailboxes. One great thing about this tool is that it has gmail “mode”. You can find manu examples at /usr/share/doc/offlineimap/examples.

Create the mailboxes file and configure offlineimaprc. You can set it up with very few lines, yet use many different options. Take my ~/.offlineimaprc as another example.


metadata = ~/.offlineimap
accounts = GmailMain

enabled = yes

# you don't need to set the mailboxes. Let

# offlineimap do it.

filename = ~/.mutt/muttrc.mailboxes

# Mutt will look into this file for mailboxes.

header = "mailboxes "
peritem = =%(foldername)s
sep = " "
footer = "\n"

[Account GmailMain]
localrepository = GmailLocal
remoterepository = GmailRemote
# query the server every 7 minutes.

autorefresh = 7
# quick = 7

[Repository GmailLocal]
type = Maildir

# Setup the same folder you want for mutt.

localfolders = ~/.mail/GMAIL

restoreatime = no

[Repository GmailRemote]
type = Gmail
remoteuser = xxxxxxxxx@gmail.com
remotehost = imap.gmail.com
# Put there your password

remotepassfile = ~/.mailpass

folderfilter = lambda foldername: foldername not in ['[Google Mail]/All Mail']
#rules out the this folder from sync (you'll hardly use it).

ssl = yes
#Ensure safe connection

You can trigger it at startup by putting offlineimap -l ~/logfile in Sessions Preferences (in Gnome). Since autorefresh is set at 7, your boxes will be regularly updated, and offlineimap will not quit on completion of retrieval.
If you want to check your mail at any time (aborting the other offlineimap instance), do offlineimap -o.

If you want to set two or more accounts, just add its name under “accounts = ” and fill up the necessary field (if Gmail, just copy+paste the settings for the first account, and alter whatever is necessary, not much).

Note: If you get foldernames with spaces from your server (i.e [Google Mail].All Mail), mutt may not be able to read them properly from the mailboxes file populated by offlineimap. Please go to the tips page.


The MTA (mail transfer agent). This simple smtp tool only offers mail sending. The setup is pretty easy. Edit ~/.msmtprc and modify the appropiate line.


account default

host smtp.gmail.com

# Some people need port 465

port 587

from xxxxxxxx@gmail.com

# The following enables a secure TLS connection with the server.

tls on

tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt

tls_starttls on

tls_certcheck on

auth on

user <gmail-user>

password <your password>

logfile ~/.msmtp.log


If you want to set another account, just duplicate the above lines, and change the name of the account.

Back to main

Written by elric80

November 21, 2009 at 4:39 pm

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: