Definition
A third-party “usability wrapper” for the official Google Gmail API, designed to simplify sending and reading emails.
Why It Matters
The official Gmail API is a “technical thicket” that can stall a project for days. EZGmail allows a developer to bypass this complexity and add robust communication features to a script in minutes. It is a prime example of why abstraction is necessary for high-velocity software development: it lets you focus on the “What” (sending notifications) rather than the “How” (OAuth token management).
Core Concepts
import ezgmail
# Sending an email
ezgmail.send('recipient@example.com', 'Hello', 'Body of the email')
# Searching for messages
threads = ezgmail.search('from:boss')
print(f"Found {len(threads)} threads.")
- Setup & Auth: Requires a
credentials.jsonfile from the Google Cloud Console. Runningezgmail.init()performs an OAuth Handshake to generate a persistenttoken.json. - Thread vs. Message Hierarchy:
GmailThread: Represents a conversation. Methods likeunread()andsearch()return lists of these.GmailMessage: Individual emails within a thread. Accessed via thethread.messagesattribute.
- Key Methods:
ezgmail.send(to, subject, body, [attachments]): Sends an email.ezgmail.unread(): Retrieves all unread conversation threads.ezgmail.search('query'): Uses standard Gmail search operators.
- Attributes:
message.subject,message.body,message.sender,message.timestamp.