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
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
A spammer to send mass emails to teachers. (Education Purposes only!)

Securly-Extension-Spammer A spammer to send mass emails to teachers. (Education Purposes only!) Setup Just go a securly blocked page(You can do this b

3 Jan 25, 2022
Fast Anonymous Email Sending Tool

Email-Fake Fast Anonymous Email Sending Tool 🏆 Github Statistics : Termux For Install: pkg install python pkg install python2 git clone https://githu

Aryan 7 May 28, 2022
Tempmail API aswell as a SMTP server.

Tempmail API/Server Tempmail API aswell as a SMTP server. Website · Report Bug · Request Feature Setup Firstly create a mongodb account, and proceed t

femboy.party 16 Mar 09, 2022
A news curator and newsletter subscription package for Django

django-newsfeed What is django-newsfeed? django-newsfeed is a news curator and newsletter subscription package for django. It can be used to create a

Maksudul Haque 179 Nov 14, 2022
This library is helpful when creating accounts, it has everything you need for this

AccountGeneratorHelper Library to facilitate accounts generation. Unofficial API for temp email services. Receive SMS from free services. Parsing and

Denis 52 Jan 07, 2023
send email & telegram message whenever an analog in is recieved

send email & telegram message whenever an analog in is recieved (so when attached to an alarm siren out it will alert via mail)

Naor Livne 2 Feb 11, 2022
:incoming_envelope: IMAP/SMTP sync system with modern APIs

Nylas Sync Engine The Nylas Sync Engine provides a RESTful API on top of a powerful email sync platform, making it easy to build apps on top of email.

Nylas 3.5k Dec 23, 2022
Euserv_extend captcha solver + pin code(Gmail)

Euserv_extend captcha solver + pin code(Gmail)

19 Nov 30, 2022
A simple email sender

Email-Sender Un semplice Email-Sender che utilizza il modulo smtplib con aggiunta di interfaccia grafica realizzata con il modulo tkinter Per il corre

Vincenzo Caliendo 0 Jan 14, 2022
A Discord Mod Mail bot made in python

Fish-Mail The mod mail bot for Fish Hosting Note: You are not allowed to remove the names in the credit command Note: If you want any ideas/commands a

28 Aug 30, 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
A simple free API that allows you to extract abuse emails from IPs.

Abuse-Email-API A simple free API that allows you to extract abuse emails from IPs. also isnt worth 500 dollars :) Requirements A Debian based OS The

Keratin 1 Dec 20, 2021
Mail-Checker is a python script that lets you see your mails directly from the terminal without having to login each time.

Mail-Checker ##Mail-Checker is a python script that lets you see your mails directly from the terminal without having to login each time. ##Before you

Siddharth Pradeep 1 Jan 12, 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
A research into mail services used by different business sectors.

A research into mail services used by different business sectors. Data, scripts and results available.

Focus Chen 1 Dec 24, 2021
A small system for writing via email.

A small system for writing via email.

0 Nov 24, 2021
You take an email and password from the combo list file and check it on mail.com

Brute-Force-mail tool information: Combo Type: email:pass Domains: All domains of the site Url: https://www.mail.com Api: ☑️ Proxy: No ☑️ The correct

6 Jun 05, 2022
Temp-SMS-Receive - A Program Which Allows You To Receive Temp SMS

Welcome to Temp-SMS-Receive 👋 A Program Which Allows You To Receive Temp SMS AP

Sandaru Ashen Fernando 21 Dec 10, 2022
Send email notification when receiving Facebook message.

Send email notification when receiving Facebook message.

Radon Rosborough 4 May 08, 2022