/pmail

Crazy simple Gmail fetching via username and password. Bells and whistles not included.

Primary LanguagePython

pmail

Build Status
Code style: black

THIS IS ALL INACCURATE FOR THE MOMENT

Basic usage

gmail = Gmail('tokens.json')
for folder in gmail.get_folders():
    print('\n\nFolder: ' + folder.name)

    for message in folder.get_emails():
        print(message.get_subject())
Folder: Important
Top 10 sweaters made from dryer lint
Exclusive adventures to watch paint dry! Act now!

Folder: Unimportant
You are two centuries behind on your rent
One trick to tell if your house is on fire
Is your car cheating on you?

Explanation

gmail = Gmail(filepath)

filepath is the path to a JSON file formatted with your Gmail username and password:

{ "username": "notmyemail@gmail.com", "password": "notmypassword" }

Gmail() returns an object that can be used to fetch your Gmail folders. .get_folders() returns a list of Folder objects:

for folder in gmail.get_folders()

The .name property of a Folder object gives the folder label. To get all emails in a folder, use .get_emails():

for message in folder.get_emails()

Email objects provide various methods to return the email components:

message.get_to()
message.get_from()
message.get_subject()

More coming soon!