A Pythonic interface for Google Mail

Related tags

Emailgmail
Overview

GMail for Python

A Pythonic interface to Google's GMail, with all the tools you'll need. Search, read and send multipart emails, archive, mark as read/unread, delete emails, and manage labels.

This library is still under development, so please forgive some of the rough edges

Heavily inspired by Kriss "nu7hatch" Kowalik's GMail for Ruby library

Author

Installation

For now, installation is manual (pip support not yet implemented) and the only requirement is to use Python 2 (2.7+ to be precise):

git clone git://github.com/charlierguo/gmail.git

Features

  • Search emails
  • Read emails
  • Emails: label, archive, delete, mark as read/unread/spam, star
  • Manage labels

Basic usage

To start, import the gmail library.

import gmail

Authenticating gmail sessions

To easily get up and running:

import gmail 

g = gmail.login(username, password)

Which will automatically log you into a GMail account. This is actually a shortcut for creating a new Gmail object:

from gmail import Gmail

g = Gmail()
g.login(username, password)
# play with your gmail...
g.logout()

You can also check if you are logged in at any time:

g = gmail.login(username, password)
g.logged_in # Should be True, AuthenticationError if login fails

OAuth authentication

If you have already received an OAuth2 access token from Google for a given user, you can easily log the user in. (Because OAuth 1.0 usage was deprecated in April 2012, this library does not currently support its usage)

gmail = gmail.authenticate(username, access_token)

Filtering emails

Get all messages in your inbox:

g.inbox().mail()

Get messages that fit some criteria:

g.inbox().mail(after=datetime.date(2013, 6, 18), before=datetime.date(2013, 8, 3))
g.inbox().mail(on=datetime.date(2009, 1, 1)
g.inbox().mail(sender="[email protected]") # "from" is reserved, use "fr" or "sender"
g.inbox().mail(to="[email protected]")

Combine flags and options:

g.inbox().mail(unread=True, sender="[email protected]")

Browsing labeled emails is similar to working with your inbox.

g.mailbox('Urgent').mail()

Every message in a conversation/thread will come as a separate message.

g.inbox().mail(unread=True, before=datetime.date(2013, 8, 3) sender="[email protected]")

Working with emails

Important: calls to mail() will return a list of empty email messages (with unique IDs). To work with labels, headers, subjects, and bodies, call fetch() on an individual message. You can call mail with prefetch=True, which will fetch the bodies automatically.

unread = g.inbox().mail(unread=True)
print unread[0].body
# None

unread[0].fetch()
print unread[0].body
# Dear ...,

Mark news past a certain date as read and archive it:

emails = g.inbox().mail(before=datetime.date(2013, 4, 18), sender="[email protected]")
for email in emails:
    email.read() # can also unread(), delete(), spam(), or star()
    email.archive()

Delete all emails from a certain person:

emails = g.inbox().mail(sender="[email protected]")
for email in emails:
    email.delete()

You can use also label method instead of mailbox:

g.label("Faxes").mail()

Add a label to a message:

email.add_label("Faxes")

Download message attachments:

for attachment in email.attachments:
    print 'Saving attachment: ' + attachment.name
    print 'Size: ' + str(attachment.size) + ' KB'
    attachment.save('attachments/' + attachment.name)

There is also few shortcuts to mark messages quickly:

email.read()
email.unread()
email.spam()
email.star()
email.unstar()

Roadmap

Copyright

  • Copyright (c) 2013 Charlie Guo

See LICENSE for details.

Owner
Charlie Guo
Charlie Guo
Generate Email, Register for anything, Get the OTP/Link

OTE : One Time Email Introduction ote is a command line utility that generates temporary email address and automatically extracts OTPs or confirmation

Somdev Sangwan 457 Jan 03, 2023
ghotok mail - lets you find available contact email addresses from target website

ghotok-mail ghotok mail - lets you find available contact email addresses from target website git clone https://github.com/josifkhan/ghotok-mail cd gh

Md Josif Khan 3 Mar 14, 2022
Send email in Python conveniently for gmail using yagmail

yagmail -- Yet Another GMAIL/SMTP client For the asynchronous asyncio version, look here: https://github.com/kootenpv/aioyagmail The goal here is to m

Pascal van Kooten 2.4k Dec 31, 2022
Suplantar mails de empresas como google, facebook, github, etc...

Suplantar mails de empresas como google, facebook, github, etc...

piter 3 Feb 05, 2022
Heimdall watchtower automatically sends you emails to notify you of the latest progress of your deep learning programs.

This software automatically sends you emails to notify you of the latest progress of your deep learning programs.

Zhenyue Qin 22 Dec 06, 2021
A Django email backend that uses a celery task for sending the email.

django-celery-email - A Celery-backed Django Email Backend A Django email backend that uses a Celery queue for out-of-band sending of the messages. Wa

Paul McLanahan 430 Dec 16, 2022
Envia-emails - A Python Program that creates emails

Envia-emails Os emails é algo muito importante e usado. Pensando nisso, eu criei

José Rodolfo 2 Mar 05, 2022
An email generator code in python language

An email generator code in python language. I have done it in the simplest way possible and with no link to an SMTP server. Generating infinite emails until CTRL+C . It is a code that can be used in

Kelvin Ndungu Wanja 1 Jan 17, 2022
A small system for writing via email.

A small system for writing via email.

0 Nov 24, 2021
An offline Phishing Email Analyzer.

An offline Phishing Email Analyzer.

Kamran Saifullah (Frog Man) 11 Oct 19, 2022
Convert emails without attachments to pdf and send as email

Email to PDF to email This script will check an imap folder for unread emails. Any unread email that does not have an attachment will be converted to

Robert Luke 21 Nov 22, 2022
This Python program generates a random email address and password from a 2 big lists and checks the generated email.

This Python program generates a random email address and password from a 2 big lists and checks the generated email.

Killin 13 Dec 04, 2022
Great script for sending and spaming emails! gmail, yahoo, outlook, hotmail.

• License • Issues • Project • Wikipedia • Я не несу ответственности за ваши действия. Скачивая программное обеспечение из этого репозитория, вы согла

He1Zen 143 Dec 24, 2022
Churn Emails Inbox - Churn Emails Inbox Using Python

Churn Emails Inbox In this project, I have used the Python programming langauge

2 Nov 13, 2022
This simple python script uses cv2 to create and mail certificates to participants of workshops.

This simple python script uses cv2 to create and mail certificates to participants of workshops. Just collect the names and email ids of participants in a csv file (i used google docs), and place it

Sounder Rajendran 0 Dec 19, 2022
Using this repository you can send mails to multiple recipients.Was created in support of Ukraine, to turn society`s attention to war.

mails-in-support-of-UA Using this repository you can send mails to multiple recipients.Was created in support of Ukraine, to turn society`s attention

Oleksii Budzinskiy 2 Mar 04, 2022
Automated email sending application.

autoMail Automated email sending application. This application sends email to a user when added to database. Email message contains the temperature of

Bhat Owais 1 Feb 12, 2022
ParaskinioTouristOffices - This program sends a message to various email adresses

ParaskinioTouristOffices This program sends a message to various email adresses.

Odysseas Psomaderis 2 Feb 11, 2022
Python IMAP for Human beings

Imbox - Python IMAP for Humans Python library for reading IMAP mailboxes and converting email content to machine readable data Requirements Python (3.

Martin Rusev 1.1k Dec 30, 2022
Kanmail - An email client that functions like a kanban board, for Mac/Windows/Docker

Kanmail - An email client that functions like a kanban board, for Mac/Windows/Docker

Oxygem 1.2k Dec 31, 2022