Export emails from Gmail

You know this, and I am behind the times, but you can in fact export almost anything stored in your Google account using the Takeout interface. It’s just lots of creating and selection categories, then asking it to create a big download for you.

To export selected emails from Gmail, you would hope to just select them by checking the boxes, then find some ‘export’ option. But you can’t. I guess webmail clients do have their limits, and in fact a quick check shows that some other webmail clients I use also do not offer this, or at least not in a transparent way.

To use Google Takeout:

  1. Select messages of interest.
  2. Click Labels and create a label, say Topic-export.
  3. Add that label to any other emails you want to export.
  4. Assuming you are logged into your Google account, go to Google Takeout to take things out of Google: https://takeout.google.com/settings/takeout.
  5. Click Deselect All.
  6. Find Mail in the list of Google content types. Scroll down or search or whatever.
  7. Check the box then click on an oval button that may well say something like All Mail Data Included.
  8. Select the labels you want to export and make sure everything else is not selected.
  9. At bottom of page, click Next Step.
  10. Choose your options — you can set up regular exports if you like.
  11. Click Create New Export.
  12. Download the export.
  13. Unzip it (if it is a zip file) and behold.

Speaking of beholding …

I unzipped the archive and got a folder called Takeout. In the folder is a Mail folder, and a HTML file. In the Mail folder is a single file called Topic-export.mbox.

I double-click the archive_browser.html file. Not much help. How do I actually get at the emails as files in my hard drive? The mbox file is a plain text file in which graphics etc are encoded into text. It can be opened with other mail programs, but what I want is a bunch of files on my computer, not having to go through them using  Thunderbird or whatever, none of which I have installed.

I’d also like to get at the attachments … on Linux… what about https://gist.github.com/georgy7/3a80bce2cd8bf2f9985c?

OK.

  1. Went to that page and copied the Python code into file (extract.py) in the same folder as the Topic-export.mbox.
  2. Edited extract.py to change all.mbox to Topic-export.mbox.
  3. In a command line window, typed: $ python3 ./extract.py.
  4. It created an attachments folder, and within that an inline_images folder, and everything was as it should be!

Brilliant!

But I still don’t have the actual messages.

Some future post. Or of course open the mbox file in Thunderbird, which any sensible person would do.

The wonder.