Python Forum

Full Version: A mail scraper for sorting emails into categories
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I would like to refresh my python knowledge by writing a simple python program which could sort gmail emails by keywords in heading and/or by sender and place them into one of 2-3 categories created by me in gmail (called "labels" in gmail).
I took several Python 2.7 courses for beginners on Coursera, including "Python for networking", but may need to refresh the information.
I can envision the basic sorting algorythm from scratch like:
---if there is "keyword1" in the email heading
------move this email into category labelled "A"
---if there is "keyword2" in the email heading
------move this email into category labelled "B"
---else
------exit


But I am unsure:
1) how to get python to login into my email
2) how to represent the email category labels in python
3) how to represent email headlines/senders in python
4) how to represent the action of moving an email into a labelled category preset in the email in Python

It seems so easy in gmail GUI, but I have thousands of emails to sort.

Can someone provide some general or whatever guidelines/info sources on this issue?
Think

I am running Python 2.7.15+ and Python 3.6.8 on Ubuntu 18.04.


Thanks a lot
1) https://developers.google.com/gmail/api/
2, 3 and 4) That is a very abstract question, if the docs link above doesn't answer it then it would help us if you were more specific.