How to back up your Gmail on Linux in four easy steps

I really like Gmail, but I also like having backups of my data just in case. Here’s how to use a simple program called getmail on Unix to backup your Gmail or Google Apps email. We’ll break this into four steps.

Gmail image

Step 0: Why getmail?

If you browse around on the web, you’ll find several options to help you download and backup your email. Here are a few:

Step 1: Install getmail

On Ubuntu 7.10 (Gutsy Gibbon), you would type

sudo apt-get install getmail4

at a terminal window. Hey, that wasn’t so bad, right? If you use a different flavor of Linux, you can download getmail and install it with a few commands like this:

cd /tmp
[Note: wget the tarball download link found at http://pyropus.ca/software/getmail/#download ]
tar xzvf getmail*.tar.gz
cd (the directory that was created)
sudo python setup.py install

Step 2: Configure Gmail and getmail

First, turn on POP in your Gmail account. Because you want a copy of all your mail, I recommend that you choose the “Enable POP for all mail” option. On the “When messages are accessed with POP” option, I would choose “Keep Gmail’s copy in the Inbox” so that Gmail still keeps your email after you back up your email.

For this example, let’s assume that your username is bob@gmail.com and your password is bobpassword. Let’s also assume that you want to back up your email into a directory called gmail-archive and that your home directory is located at /home/bob/.

I have to describe a little about how mail is stored in Unix. There are a couple well-known methods to store email: mbox and Maildir. When mail is stored in mbox format, all your mail is concatenated together in one huge file. In the Maildir format, each email is stored in a separate file. Needless to say, each method has different strengths and weaknesses. For the time being, let’s assume that you want your email in one big file (the mbox format) and work through an example.

Example with mbox format

– Make a directory called “.getmail” in your home directory with the command “mkdir ~/.getmail”. This directory will store your configuration data and the debugging logs that getmail generates.
– Make a directory called gmail-archive with the command “mkdir ~/gmail-archive”. This directory will store your email.
– Make a file ~/.getmail/getmail.gmail and put the following text in it:

[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = bob@gmail.com
password = bobpassword

[destination]
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

[options]
# print messages about each action (verbose = 2)
# Other options:
# 0 prints only warnings and errors
# 1 prints messages about retrieving and deleting messages only
verbose = 2
message_log = ~/.getmail/gmail.log

Added: Run the command “touch ~/gmail-archive/gmail-backup.mbox” . If you change the path in the file above, touch whatever filename you used. This command creates an empty file that getmail can then append to.

The file format should be pretty self-explanatory. You’re telling getmail to fetch your email from pop.gmail.com via a POP3 connection over SSL (which prevents people from seeing your email as it passes between Gmail and your computer). The [destination] section tells where to save your email, and in what format. The “Mboxrd” is a flavor of the mbox format — read this page on mbox formats if you’re really interested. Finally, we set options so that getmail generates a verbose log file that will help in case there are any snags.

Example with Maildir format

Suppose you prefer Maildir instead? You’d still run “mkdir ~/.getmail” and “mkdir ~/gmail-archive”. But the Maildir format uses three directories (tmp, new, and cur). We need to make those directories, so type “mkdir ~/gmail-archive/tmp ~/gmail-archive/new ~/gmail-archive/cur” as well. In addition, change the [destination] section to say

[destination]
type = Maildir
path = ~/gmail-archive/

Otherwise your configuration file is the same.

Step 3: Run getmail

The good news is that step 2 was the hard part. Run getmail with a command like “getmail -r /home/bob/.getmail/getmail.gmail” (use the path to the config file that you made in Step 2). With any luck, you’ll see something like

getmail version 4.6.5
Copyright (C) 1998-2006 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3SSLRetriever:bob@gmail.com@pop.gmail.com:995:
msg 1/99 (7619 bytes) from <info@example.com> delivered to Mboxrd /home/bob/gmail-archive/gmail-backup.mbox
msg 2/99 (6634 bytes) from <sales@example.com> delivered to Mboxrd /home/bob/gmail-archive/gmail-backup.mbox

99 messages retrieved, 0 skipped
Summary:
Retrieved 99 messages from SimplePOP3SSLRetriever:bob@gmail.com@pop.gmail.com:995

Hooray! It works! But wait — I have over 99 messages, you say. Why did it only download 99 messages? The short answer is that Gmail will only let you down a few hundred emails at a time. You can repeat the command (let getmail finish each time before you run it again) until all of your email is downloaded.

Step 4: Download new email automatically

A backup is a snapshot of your email at one point in time, but it’s even better if you download and save new email automatically. (This step will also come in handy if you have a ton of Gmail and don’t want to run the command from Step 3 over and over again for hours to download all your mail.)

We’re going to make a simple cron job that runs periodically to download new email and preserve it. First, make a very short file called /home/bob/fetch-email.sh and put the following text in the file:

#!/bin/bash
# Note: -q means fetch quietly so that this program is silent
/usr/bin/getmail -q -r /home/bob/.getmail/getmail.gmail

Make sure that the file is readable/executable with the command “chmod u+rx /home/bob/fetch-email.sh”. If you want to make sure the program works, run the command “/home/bob/fetch-email.sh”. The program should execute without generating any output, but if there’s new email waiting for you it will be downloaded. This script needs to be silent or else you’ll get warnings when you run the script using cron.

Now type the command “crontab -e” and add the following entry to your crontab:

# Every 10 minutes (at 7 minutes past the hour), fetch my email
7,17,27,37,47,57 * * * * /home/bob/fetch-email.sh

This crontab entry tells cron “Every 10 minutes, run the script fetch-email.sh”. If you wanted to check less often (maybe once an hour), change “7,17,27,37,47,57” to “7” and the cron job will run at 7 minutes after every hour. That’s it — you’re done! Enjoy the feeling of having a Gmail backup in case your net connection goes down.

Bonus info: Back up in both mail formats at once!

As I mentioned, mbox and Maildir have different advantages. The mbox format is convenient because you only need to keep track of one file, but editing/deleting email from that huge file is a pain. And when one program is trying to write new email while another program is trying to edit the file, things can sometimes go wrong unless both programs are careful. Maildir is more robust, but it chews through inodes because each email is a separate file. It also can be harder to process Maildir files with regular Unix command-line tools, just because there are so many email files.

Why not archive your email in both formats just to be safe? The getmail program can easily support this. Just change your [destination] information to look like this:

[destination]
type = MultiDestination
destinations = (‘[mboxrd-destination]’, ‘[maildir-destination]’)

[mboxrd-destination]
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

[maildir-destination]
type = Maildir
path = ~/gmail-archive/

Note that you’ll still have to run all the “mkdir” commands to make the “gmail-archive” directory, as well as the tmp, new, and cur directories under the gmail-archive directory.

Bonus reading!

What, you’re still here? Okay, if you’re still reading, here’s a few pointers you might be interested in:
– The main getmail site includes a page with lots of getmail examples of configuration files. The getmail website has a ton of great documentation, too. Major props to Charles Cazabon for his getmail program.
– This write-up from about a year ago covers how to back up Gmail as well.
– The author of getmail seems to hang out quite a bit on this getmail mailing list. See the main site for directions on signing up for the list.
– If you’re interested in a more powerful setup (e.g. using Gmail + getmail + procmail), this is a useful page.
– For the truly sadistic, learn the difference between a Mail User Agent (MUA) and a Mail Transfer Agent (MTA) and how email really gets delivered in Unix.
– I’ve been meaning to write all this down for months. Jeff Atwood’s recent post finally pushed me over the edge. Jeff describes a program that offers to “archive your Gmail” for $29.95, but when you give the program your username/password it secretly mails your username/password to the program’s creator. That’s pretty much pure evil in my book. And the G-Archiver program isn’t even needed! Because Gmail will export your email for free using POP or IMAP, it’s not hard to archive your Gmail. So I wrote up how I back up my Gmail in case it helps anyone else. Enjoy!

Added March 16, 2008: Several people have added helpful comments. One of my favorites led me to a post by commenter Peng about how to back up Gmail with IMAP using getmail. Peng describes how to back up the email by label as well. He mentions that you could use the search “after:2007/1/1 before:2007/3/31” and assign the label FY07Q1 to the search results, for example. Then you can back up that single label/mailbox by making the getmail config file look like this:

[retriever]
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
username = username
password = password
mailboxes = (“FY07Q1”,)

[destination]
type = Mboxrd
path = ~/.getmail/gmail-backup-FY07Q1.mbox

Peng also mentions a nice bonus: since you’re backing up via IMAP instead of POP, there’s no download limit. That means that you don’t have to run the getmail program repeatedly. Thanks for mentioning that Peng!

71 Responses to How to back up your Gmail on Linux in four easy steps (Leave a comment)

  1. Are you afraid of losing your information? I thought that Gmail would never in danger of losing anything

  2. I would just like to add that this works for email managed by Google Apps For Your Domain. For username, put your full email address: you@example.com or whatever. Server is still pop.gmail.com.

  3. Lino Uruรฑuela, I’m not afraid of that, but it always pays to have a backup.

    Mark, good point. I might mention that in the post if I update it.

  4. Does anyone know of a similar guide to Matt’s, but for OS X?

    Thanks!

  5. Humm!!!
    And I thought that Gmail is always backed up by some Samaritans while we sleep ๐Ÿ™‚

    I’ll have to think twice over it now.

    I worry more about forgetting password then loosing mails..

  6. This is great. GMail’s security was recently compromised and although it’s probably the most reliable of all the popular email services, backing up is never a ad option.

  7. Some time ago I heard about Gmail accounts being closed because they had too much traffic. It might have been because they were trying to download all their mails. Do you know whether it’s safe to do a full back up — downloading over 1 GB in an hour –, or will my Gmail account get deleted? (Not sure whether I understood it all correctly and the account suspending thing wasn’t just FUD…)

  8. You can’t “back up” Gmail with Mac OS X Mail.app, I don’t believe. You can use Mail.app instead of the Gmail interface, but if you want to use the Gmail interface and back up to Mail.app, it doesn’t work: It won’t get your Sent mail, it will screw up your inbox by marking things read, etc.

  9. Thanks for this. I need to make a backup and the directions just don’t get any easier to follow that these… ๐Ÿ™‚

  10. Matt,

    Do you guys have a business solution where we can use the gmail software, but using our own domain name? I simply want our employees to use the gmail software because it is the only practical email system I know of that doesn’t make emails dissapear when a spam filter is used. Other systems that I know have to learn first, and you constantly have to send special emails to say which emails are allowed and which are not. The Gmail software does that much better and has the enormous advantage that it is all in the same screen.

    I’m going nuts with employees and customers complaining they can’t email some people and finding out that the spamfilter has caught the emails. Teaching employees that they have to teach the filter what to let through and what is real spam is at best a waste of time.

    In Gmail you have to the same thing, but it’s much simpler to use and everybody figures it without any help.

    So if Google has this, can you let me know where I can find this service? In the business solutions page I couldn’t find it.

    Thanks,

    Peter

  11. that’s funny. back up is mainly what i use gmail FOR.

  12. Peter,
    Have you heard of Google Apps? http://www.google.com/a I think it’s exactly what you’re looking for.

    Alt

  13. I like Gmail too, I have more than 6GB now, do not need to backup anything.When i receive email with OE, i leave a copy of my email on Gmail, so i can read my past emails at anytime and anywhere.

  14. Do you guys have a business solution where we can use the gmail software, but using our own domain name?

    Absolutely, Peter (IMC). Check out Google Apps for Your Domain: “Google Apps lets you offer email, instant messaging, and calendar accounts on your own domain name (for example, jsmith@your-group.com), to keep your group close and build its online identity.”

    Sander, if you use the instructions I’ve given you, you’re going to be doing a very “polite” backup and I don’t expect you’d have any problems. If you were checking for new email all the time, then it might be different.

    Bruce, I’m glad the instructions are easy-to-follow. It took a while to try to make it clear.

  15. Thanks for the tip.

  16. Thanks Matt!

  17. Google Apps for my domain. That is a must have… free too! Thanks Matt (and Google)!

  18. Matt, a better title for this post might have included the more reasonable assertion that you can back up your email “in four steps.” Easy?

  19. What about backing up google docs?

    Right now the only way I see it can be done is if you export each one individually.

  20. Interesting article – thanks!

    Why use POP3 and not IMAP though?

    Thanks

    Ian

  21. Well done thanks. Mail is one of the last big secrets for me ๐Ÿ™

    In debian etch i had to touch /home/macdet/gmail-archive/gmail-backup.mbox an to start it twice

    i collect some infos abount in my wiki. say it to google ๐Ÿ™‚

    http://wiki.mobbing-gegner.de/Linux/Internet/Mail

    Anyway good infos and y nice feeling to have gmail on the lap

    macdet

  22. Nice! And don’t forget to backup your blog with http://blogbackupr.com for example

  23. I’m wondering the same thing as Ian. My mail needs to get processed: I add tags, delete mails, tag mails as spam, flag mails, … If I backup using pop, all my tags will be lost, deleted messages will stay on my backup, … Using a mail client like Mail.app or Thunderbird and accessing GMail through IMAP would give me a backup solution I want, but I wonder if there’s a command-line utility to synchronize IMAP mailboxes (in one direction). Any suggestions?

  24. This is a nice article, thanks.

    There is however a problem with the ststus (read/unrad) of the gmail mails when backing them up with this method. POP will not keep the status, IMAP in principle can but there are some discussion about how much it is compliant with RFC.

    Lars Schillingmann has the solution. His initial post in the getmail list is not available anymore but you will get the idea form that email fragment:
    “The basic idea is to exchange the fetch command by a peek command (as described in the imap RFC). That works with getmail because it does not use the seen status in order to decide if a mail has to be downloaded but uses its own index for that.”

    I made the change two years ago or so in the getmail sources and it worked perfectly (= the read/unread status was maintained).

  25. Anyone ever uses ClarkConnect? It has an email server build in even for the free Community version. Can I setup CC to download a copy of the emails from Gmail via IMAP? I then access these emails from CC directly from my home or office and only access Gmail on Google when I am on the road. Since the emails are synched, whatever is done on the CC server is synched to the Gmail server. Is this possible? Basically the idea here is instead of each person at the office does his own backup on his personal computer, we have a centralized backup server that is CC. Considering how bad the non-IT people backup their data, it is best to stored the data on a centralized server so IT can monitor and backup the data for them.

  26. Great tips! Thanks.

    Just read the documentation of getmail and noticed that in case of the mbox format, the .mbox file should exist before you run getmail, i.e. getmail will not create that file if it is not created.

    Also, being afraid of a huge .mbox file, I devided my mails using Gmail’s label feature into several small portions, like FY06Q3, FY06Q4 … etc., and I use getmail thru SimpleIMAPSSLReciever which enables me to fetch only one of those labels at a time.

  27. I recently set up gmail to pick up my mail using pop from my main domain email accounts. I did this because sometimes I had trouble accessing my email from certain places. But since a lot of places ban gmail this became a bit useless. So now I just use gmail to back up my mail for free. Seems this is a good way for me to do a restore then!!!

  28. I once used mpop to backup my gmail account. Unfortunately I could (for some reason) not get to all my messages. Which is scary and really annoying.

    http://vafer.org/blog/20070103073735

  29. “What about backing up google docs?

    Right now the only way I see it can be done is if you export each one individually.”

    Try this post: http://googlesystem.blogspot.com/2007/05/export-all-your-documents-from-google.html

    And to backup your other Google Apps account info, these are handy:
    http://lifehacker.com/software/hack-attack/back-up-your-google-apps-data-281635.php
    http://googlesystem.blogspot.com/2007/12/creating-backup-for-your-google-account.html

    “Why use POP3 and not IMAP though?”

    Ian Chilton, that was just what I used. I started on this path before IMAP rolled out, so I ended up sticking with POP3 instructions.

    Wojtek, thanks for contributing that advice–good to know.

    Peng, good point. I updated the post to mention that you need to create the mbox file before running getmail. Nice tip on using SimpleIMAPSSLReceiver to fetch by label, too. Do you have a blog post or url pointer where you’ve documented exactly what you did?

    Added: Ah, here it is: http://dengpeng.name/blog/2008/03/17/backup-gmail-via-imap-using-getmail/ Nice write-up, Peng! That’s a great description of how to back up via IMAP as well.

  30. hi
    what about security?
    if i write in the script my login + password
    i noticed that it is send via ssl but

    as i don’t know much in this matter, is it really safe?

    i kown for sure people smarter than me are interested in accessing other people gmail accounts

  31. dondiba, if you leave the password out of the configuration file, getmail will prompt you for it. So you have the choice.

  32. Lifehacker posted a great guide on how to make Thunderbird’s IMAP and Gmail sync up to each other, so that an action taken like “archive” or “mark read” in one interface updates the other interface.

  33. This is really a great find, but I’m having a problem that it seems no one else is. I set up getmail as described in Peng’s blog (while it was still available) and it does work. However, even though it’s IMAP, I’m only getting 275 messages down at a time. I’m not using any extra options, but looking over the getmail configs it seems the only restriction on downloads from that end would be total size, which even if it was set would vary each time.

    I’ve searched everywhere I can find with nothing. Do you have any idea what would cause this limit? I’m using mbox and not specifying any particular label (mailboxes variable commented out). Any help is appreciated, I’m excited to have such a simple answer to a gmail backup ๐Ÿ™‚

  34. I would like to point out that, although I did not use the method above, backing up my gmail account proved useful for me when I must not have fully logged out of a public computer and someone got on my gmail account and deleted everything.

    I already had a backup email account setup in gmail which all mail was forwarded to. I never lost anything.

  35. You can use:

    */10 * * * * cmd

    to download the emails every 10 minutes; much better than your crontab line ๐Ÿ˜›

  36. I just prefer Offlineimap, which worths a look.

  37. It is my impression using POP with getmail would back up everything in Gmail as of it’s current state at the download time. Deleted emails and label changes in the Gmail interface after the fact would not be reflected in the archive. Is this correct?

    If so, would using IMAP with getmail keep the 2 in sync? If not, are there other methods to do this with a command line email client so it could happen invisibly on my home server?

    Thanks

  38. You can use
    mailboxes = (“[Gmail]/All Mail”,)
    to download all mails.

    I thing you should mention the imap solution first in your post, before pop. ๐Ÿ˜‰

  39. I’ve written a wrapper cli for getmail4 that pretty much automates your steps. It’s called ImapGrab, and it can be used for any IMAP server. I also added a special option for Gmail. Enjoy!
    http://daylightpirates.org/index.php/Programs/ImapGrab

  40. Hi,

    I noticed that all the discussion is all about backing up. However, how do I restore this back to an IMAP account? This would not be nice in case for restoring accidentally deleted mails. I would also be a nice feature for transferring IMAP email accounts from one provider to another.

    Any suggestions?

  41. wow! No offense, but you call this easy? I’m so glad that I use Windows and can find a gmail backup tool like this one: http://www.gmailkeeper.com

    It’s still in beta stage and I’m one of the testers and am very happy with it ๐Ÿ˜‰

    Ken

  42. FYI, it seems that the new link for Peng’s post is here:

    http://b.pengdeng.com/2008/03/backup-gmail-via-imap-using-getmail_16.html

    The old link is broken.

  43. I suppose to add this to config file under [options]:

    # preserves your mail after backup
    delete = false
    # just get new mails
    read_all = false

  44. uh .. sorry if this is a stupid question, in defining [destination] is there anyway of pointing the download to a specific IMAP folder if I’ve created on? Meaning, I built a IMAP server I want to import email, but dump it into a IMAP folder.

    Couldn’t quite make out a method to do that from the getmail site, thought I’d give it a shot and ask here.

    Thanks.

  45. From this: if you are to download all yor mail, use
    mailboxes = ("[Google Mail]/All Mail",)

  46. The IMAP setup worked flawlessly. I’ve been looking for a couple of days for a way to only backup certain labels, this page was exactly what I needed. Thanks so much.

  47. Will this method also work to backup my Gmail sent mail or only received?

  48. Thanks for the helpful post, backing up this way seems to work well. Just a couple of notes from trying it out:
    One line of the multiple destinations config isn’t quite right – it should have normal single quotes rather than the characters you get if you cut and paste (back ticks I think?):
    Incorrect (gives a syntax error when run):
    destinations = (‘[mboxrd-destination]’, ‘[maildir-destination]’)
    Correct:
    destinations = (‘[mboxrd-destination]’, ‘[maildir-destination]’)
    If you squint you can see the difference ๐Ÿ™‚

    Secondly, it seems to be a good idea to set options to ignore messages that have already been retrieved – under the [options] section, I added:
    read_all = false

    This causes getmail to track retrieved messages in an “oldmail-xxxxx” file. Otherwise, you will get a new copy of each message each time you download, at least with IMAP. POP may work differently (especially on gmail, I think it “deletes” downloaded messages for you).

  49. Well thanks again for the post. I used this flawlessly about a year ago, but it seems now things have gotten updated.

    On step 4: creating a shell script, python has had a few updates since your post. When the script is run manually instead of running quietly it spits out this: andy@andy-desktop:~$ ~/.getmail/amixinlife.sh
    /usr/share/getmail4/getmailcore/baseclasses.py:26: DeprecationWarning: the sets module is deprecated
    import sets

    Any suggestions to quiet this script?

  50. How to download only specific labeled mails from Gmail? e.g. I just want want to download the messages from drafts/sent mails.
    Thanks in advance.

  51. How does one restore (and yes, I checked for a putmail and putmail4)

  52. @Andrew January 6, 2010 at 6:53 am

    The easiest way to hide those error message is to redirect stderr:

    ~/.getmail/amixinlife.sh 2>/dev/null

  53. A little security related hint.
    Be sure to chmod 600 the file you created containing the google account credentials (in the article ~/.getmail/getmail.gmail), just to be sure that any logged in user can’t read it.
    Useless to say that this article was very useful ๐Ÿ™‚ Oh, well, it’s not useless at all! Great job Matt ๐Ÿ˜‰

  54. Thank you for this great tutorial! Saved me a pile of time (backing up my mum’s gmail right now for her). Suggestion: Maybe move the tip about IMAP from Peng to the top of the post, as it saves a heap of time (and that’s the whole idea of using the command line instead of Evolution or Thunderbird to do this, right?). Thanks again Matt!

  55. Just a comment in case someone else is as dense as I am. I copied the config file for pop3 and pasted it into gedit to modify and save. This caused everything to be tabbed over from the left-hand edge. Until I removed the tabs and aligned everything to the left the config file would not work, getmail threw lots of errors. Now it’s working fine. Thanks for a very useful article.

  56. FWIW if you’re using CentOS/RedHat, you can install the DAG repos for yum and just install getmail with yum like this:

    yum install getmail

    Install the DAG repo first: Dag repo installation guide – http://dag.wieers.com/rpm/FAQ.php#B

    Thanks Matt for the clear instructions.

  57. Hi and thanks for this useful post.

    There’s a mistake in the text. The search string should be: “after:2007/1/1 before:2007/4/1”

  58. The problem with backing up with IMAP — which for some reason neither Matt nor anyone else has mentioned — is that it marks ALL backed up mail as read. Ugh.

    I get tons of mail and one of the most useful pieces of info I have is whether a message is read. I would say at least a quarter of the searches I run in Gmail use the “is:read” modifier. Well, I just nuked that information on all my old mail. Back up via IMAP if you want but do not sell it is as some nice solution. It’s as much of a crappy hack as POP backup.

    POP access, at least, can be set in the GMail settings to not affect message read marking. But then there’s some kind of access limit. Ugh. Blech.

  59. Thanks for the post. I’m using Ubuntu 10.10 and followed all of the above instructions, but I keep on getting a configuration error: (mailboxes incorrect format (invalid syntax (, line 1)))

    My config file is as follows:

    [retriever]
    type = SimpleIMAPSSLRetriever
    server = imap.gmail.com
    username = hugmin42@gmail.com
    password = mypassword
    mailboxes = (โ€œEvaโ€ณ,)

    [destination]
    type = Mboxrd
    path = ~/gmail-archive/gmail-backup-Eva.mbox

  60. Hello guys,

    Here is a simple solution for backing up your mail through Beyond Inbox http://www.beyondinbox.com/ , which let you keep your email organized and inbox clean so that you can find a message when you need it. At the same time, you also need to make sure that you archive and backup your email to prevent the loss in situations like accidental loss of data from email servers, hacking of account, forget password, over size inbox or unpredictable scenarios.
    There are five basic functions that we all need to perform in order to manage and safeguard our email- backup, restore, archive, transfer and organize the data. Beyond Inbox can help you perform all of these in a very efficient and easy way.
    Using Beyond Inbox, you can backup, restore, archive, transfer or organize email from any IMAP enabled email account.

    Beyond Inbox is available in two different flavors i.e. an easy User Interface and Command line interface.

    You can use this tool on Windows, Linux as well as Mac OSX. Click here to download http://www.beyondinbox.com/beyondinbox-download.html

    You can easily install beyond Inbox. See the link http://www.beyondinbox.com/documentation/mail-backup–how-to-install-beyondinbox.html

  61. This is the getmail.gmail I use, and it works well.

    You have to run it multiple times initially (can use “for {1..n}; do getmail -r ~/.getmail/getmail.gmail; done”) where “n” is the number of thousand emails you have (rounded up).

    From then on (eg weekly) 1000 is probably enough that running it once will suffice. I use maildir for storage as it seems to be more reliable and you don’t run into locking problems, dealing with a massive file, etc.

    You need to create the folder and have it writeable, along with three subfolders: cur, new and tmp.


    [retriever]
    type = SimpleIMAPSSLRetriever
    server = imap.gmail.com
    username = xxx
    password = xxx
    mailboxes = ( "[Gmail]/All Mail", "[Gmail]/Sent Mail", "[Gmail]/Drafts" )

    [destination]
    type = Maildir
    path = /home/dan/gmail-archive/maildir/

    [options]
    # print messages about each action (verbose = 2)
    # Other options:
    # 0 prints only warnings and errors
    # 1 prints messages about retrieving and deleting messages only
    verbose = 2
    message_log = ~/.getmail/gmail.log
    read_all = False
    max_messages_per_session = 1000
    received = false
    delete = false

    Hope this helps someone. Still has the unfortunate side effect of flagging mail as read. Other IMAP clients manage this trick, not sure why getmail doesn’t.

  62. Thanks for the post ๐Ÿ™‚

    When doing my initial gmail import there were thousands of emails to download initially, and I didn’t want to sit there and keep running the import script, I also didn’t know exactly how long it would take for each run to time a cron (gmail seems to send back anything from 99 to 2k at a time).

    So I modified your shell script to create a file lock to avoid the cron “running over itself”:


    #!/bin/bash
    if [ -f /tmp/fetch-gmail.pid ]; then
    echo 'Already running - exiting;';
    exit;
    fi
    touch /tmp/fetch-gmail.pid
    /usr/bin/getmail -q -r /home/bob/.getmail/getmail.gmail
    rm -f /tmp/fetch-gmail.pid

  63. I don’t know too much about what I’m doing but I used this bash script:

    #!/bin/bash

    i="1"

    while [ $i -gt 0 ]
    do
    getmail -r /home/david/.getmail/getmail.gmail
    done

    of course it’s going to eventually start to error out… but that should be after it runs a few hundred times ๐Ÿ™‚

  64. Ok, You all post how to backup. Some guys ask how to RESTORE this mail to imap server. Could You write something about this?

  65. Ben Woodcroft

    Hi,

    Thanks for writing this useful tool. I noticed that you suggest people might put their username in the “getmail.gmail” file. However, this seems rather insecure to me. As it stands, any other user on the computer will be able to read that file. At the very least I’d say don’t give anyone permissions except yourself:

    $ chmod go-rwx ~/.getmail/getmail.gmail

    But even then anyone with root privileges, or anyone who can boot your machine into a root prompt (no password required), will be able to read your password.

  66. Restoring the backed-up mail to an IMAP server will be different for each type of IMAP server. What I’ve done in the past is set up a mail client like Thunderbird, point it to the backed-up mail archive, and created a second account for the new IMAP server. Then I just copied the backed-up mail from the backup folder to the new IMAP account.

  67. Thank you, Matt, for a great blog post.

    I just set up getmail with POP as described in the original post and successfully backed up all my mail for two Gmail accounts, but I’m confused by the message counts I am seeing in the Gmail web interface versus mutt.

    Gmail account 1: 3930 messages when I click “Inbox” in the web interface, 5410 when I click “All Mail” in the web interface, 4523 when I open the mbox file in mutt. The web interface reports 686 MB total; mutt shows 448 MB.

    Gmail account 2: 1861 messages when I click “Inbox” in the web interface, 9063 when I click “All Mail” in the web interface, 8198 when I open the mbox file in mutt. The web interface reports 135 MB total; mutt shows 122 MB.

    (To look at the mbox in mutt I’m running `mutt -R -f /path/to/foo.mbox`)

    Obviously, the message counts from mutt are closer to the “All Mail” counts than the “Inbox” counts, and I feel like this backup is good enough, but can anyone explain the discrepancy?

  68. Hello,
    I was wondering if it’s possible to have getmail retrieve several folders from gmail, but to keep them seperate.

    For example:
    I’ve got two folders in gmail called: Shipping and Ack”

    So I’m assuming I’d setup mailboxes like this:
    mailboxes=( “[Gmail]/Shipping”, “[Gmail]/Ack” )

    But I’m not sure how to setup the destination so that Shipping and Ack are separate from each other.

    Is this even possible?

    Thank you.

    –Mike

  69. Would this include attachments and sent mail as well? WOuld it retain archive statuses and (nested) labels with special-chars in names? Chats?

    Thanks for this.

  70. jonathan@ubuntu:~$ sudo apt-get install getmail4
    [sudo] password for jonathan:
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    You might want to run ‘apt-get -f install’ to correct these:
    The following packages have unmet dependencies.
    freemind-plugins-time : Depends: openjdk-6-jre but it is not going to be installed or
    sun-java5-jre but it is not installable or
    sun-java6-jre but it is not installable or
    java2-runtime
    Depends: freemind (= 0.8.1-2) but it is not going to be installed
    Depends: libjcalendar-java but it is not going to be installed
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
    jonathan@ubuntu:~$
    jonathan@ubuntu:~$ sudo apt-get -f install getmail4
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    You might want to run ‘apt-get -f install’ to correct these:
    The following packages have unmet dependencies.
    freemind-plugins-time : Depends: openjdk-6-jre but it is not going to be installed or
    sun-java5-jre but it is not installable or
    sun-java6-jre but it is not installable or
    java2-runtime
    Depends: freemind (= 0.8.1-2) but it is not going to be installed
    Depends: libjcalendar-java but it is not going to be installed
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
    jonathan@ubuntu:~$

css.php