Creating a local backup for your Emails

Do you want to download your Emails to your local system? Does your email provider not allow you to download specific emails? Do you have a some knowledge of Python Scripting?  If your answers to your above questions were “yes”, then you’ve come to the right place.If you want to get all your Emails data at one go, you can follow this video(for Gmail).

For the purposes of this tutorial we will be using the imap protocol to access and download the mail content.

TL;DR – Here’s the code gist

1. Logging to the Email service

Protip: You might want to use app passwords instead of your original password.

2. Selecting a mailbox

A mailbox is a folder that you can use to sort your emails. Some common mailboxes are – “[Gmail]/Starred”,”[Gmail]/Spam”,”INBOX”.
Display a list of all available mailboxes with the following code:.

and then select a mailbox using

conn.select(mailbox)

3. Getting the Email content

You might want to refer to IMAP search manual before you start using this parameter. The default parameter is ALL.

Putting it all together

2 comments On Creating a local backup for your Emails

Leave a Reply to ashish Cancel Reply

Your email address will not be published.

Site Footer

Sliding Sidebar

About Me

About Me

Hey, I am Thomas Ashish Cherian. What I cannot create, I do not understand.

Social Profiles