项目作者: hallazzang

项目描述 :
Pythonic Gmail client
高级语言: Python
项目地址: git://github.com/hallazzang/gmaily.git
创建时间: 2018-01-27T07:52:32Z
项目社区:https://github.com/hallazzang/gmaily

开源协议:

下载


gmaily

Unofficial Gmail python client with pythonic API.

Features

  • Clean API
  • No other dependencies than standard library
  • Lazy loading for content

Example

  1. import sys
  2. import getpass
  3. import datetime
  4. from gmaily import Gmaily
  5. g = Gmaily()
  6. user_email = input("Email: ")
  7. user_pw = getpass.getpass()
  8. if not g.login(user_email, user_pw):
  9. print("Cannot login")
  10. sys.exit(1)
  11. msgs = g.inbox().after(datetime.date.today() - datetime.timedelta(weeks=2))
  12. for msg in msgs.all():
  13. print("\n" + (" Mail UID: %d " % msg.uid).center(80, "=") + "\n")
  14. print("Subject:", msg.subject)
  15. print("From:", msg.sender)
  16. print("Date:", msg.date)
  17. print("Attachments:", msg.attachments)
  18. print("-" * 10)
  19. print(msg.text)
  20. g.logout()

Usage

Searching Mailbox

SearchQuery, which is returned by some methods like Gmaily.inbox
supports method chaining and you can easily mix search criterias together:

  1. two_weeks_ago = datetime.date.today() - datetime.timedelta(weeks=2)
  2. msgs = g.inbox().by("john@example.com").before(two_weeks_ago)

Alternatively, you can use other mailboxes than INBOX in the above example
using Gmaily.mailbox method:

  1. msgs = g.mailbox("URGENT").on(datetime.date.today())

You can then execute the query and fetch the results using SearchQuery.all:

  1. print(msgs.all())

You can find the full list of supported criterias and their description at
here.
Note that ALL criteria is not present because it’s the default criteria
and SearchQuery.all stands for executing the query.
Any other names like .fetch(), .do() could be taken the place,
but I chose the .all() because famous ORMs use it too.

Some other criterias are omitted too:

  • NOT
  • OR
  • UID

Installation

It requires Python>=3.5.

  1. $ pip3 install -U gmaily

License

MIT