Multi-account Gmail management system with full CRUD operations, unified inbox, and attachment handling.
📋 For complete project details, see PROJECT_SUMMARY.md
- Manage 7 Gmail accounts from one interface
- Unified inbox (see all emails from all accounts together)
- Full CRUD operations with Gmail API
- Email body parsing (plain text + HTML)
- Attachment download capabilities
uv pip install -r requirements.txtOr install packages directly:
uv pip install google-api-python-client google-auth-httplib2 google-auth-oauthlibpython gmail_crud.pyOn first run, it will:
- Open browser for OAuth authentication
- Ask you to authorize the app
- Save credentials to
token.jsonfor future use
list_messages(max_results, query)- List messages from inboxget_message(msg_id)- Get full message by IDsearch_messages(query)- Search messages with Gmail query syntaxget_message_details(msg_id)- Get formatted message detailsget_message_body(msg_id)- Get full email body (plain text and HTML)list_attachments(msg_id)- List all attachments in a messagedownload_attachment(msg_id, attachment_id, filename, save_dir)- Download single attachmentdownload_all_attachments(msg_id, save_dir)- Download all attachments from a message
send_message(to, subject, body, attachments)- Send email with optional attachments
mark_as_read(msg_ids)- Mark messages as readmark_as_unread(msg_ids)- Mark messages as unreadadd_labels(msg_ids, label_ids)- Add labels to messagesremove_labels(msg_ids, label_ids)- Remove labels from messages
trash_messages(msg_ids)- Move to trash (recoverable)delete_messages(msg_ids)- Permanently deleteuntrash_messages(msg_ids)- Restore from trash
list_labels()- Get all available labels
from gmail_crud import GmailCRUD
# Initialize
gmail = GmailCRUD()
# List recent emails
messages = gmail.list_messages(max_results=10)
# Search unread emails
unread = gmail.search_messages('is:unread')
# Read full email body
body = gmail.get_message_body(msg_id)
print(body['plain']) # Plain text
print(body['html']) # HTML version
# List and download attachments
attachments = gmail.list_attachments(msg_id)
for att in attachments:
print(f"{att['filename']} - {att['size']} bytes")
gmail.download_all_attachments(msg_id, save_dir='./downloads')
# Send email
gmail.send_message(
to='recipient@example.com',
subject='Test Email',
body='Hello from Gmail API!',
attachments=['file.pdf']
)
# Mark as read
gmail.mark_as_read(msg_id)
# Trash message
gmail.trash_messages(msg_id)is:unread- Unread messagesfrom:example@gmail.com- From specific sendersubject:invoice- Messages with subject containing "invoice"has:attachment- Messages with attachmentsafter:2024/01/01- Messages after dateis:starred- Starred messages
gmail_crud.py- Main CRUD implementationtoken.json- OAuth tokens (auto-generated, DO NOT commit)client_secret_*.json- OAuth credentialscred.txt- Credential reference
- Add email body parsing (HTML/Plain text)
- Implement draft operations
- Add attachment download functionality
- Create CLI interface
- Add bulk operations
- Implement rate limiting
- Add logging
- Create unit tests