GmailToolkit
init
- timeout (Optional[float]): The timeout value for API requests in seconds. If None, no timeout is applied. (default: :obj:
None)
people_service
people_service
send_email
- to (Union[str, List[str]]): Recipient email address(es).
- subject (str): Email subject.
- body (str): Email body content.
- cc (Optional[Union[str, List[str]]]): CC recipient email address(es).
- bcc (Optional[Union[str, List[str]]]): BCC recipient email address(es).
- attachments (Optional[List[str]]): List of file paths to attach.
- is_html (bool): Whether the body is HTML format. Set to True when sending formatted emails with HTML tags (e.g., bold, links, images). Use False (default) for plain text emails.
reply_to_email
- message_id (str): The unique identifier of the message to reply to. To get a message ID, first use fetch_emails() to list messages, or use the ‘message_id’ returned from send_email() or create_email_draft().
- reply_body (str): The reply message body.
- reply_all (bool): Whether to reply to all recipients.
- is_html (bool): Whether the body is HTML format. Set to True when sending formatted emails with HTML tags (e.g., bold, links, images). Use False (default) for plain text emails.
forward_email
- message_id (str): The unique identifier of the message to forward. To get a message ID, first use fetch_emails() to list messages, or use the ‘message_id’ returned from send_email() or create_email_draft().
- to (Union[str, List[str]]): Recipient email address(es).
- forward_body (Optional[str]): Additional message to include at the top of the forwarded email, before the original message content. If not provided, only the original message will be forwarded.
- cc (Optional[Union[str, List[str]]]): CC recipient email address(es).
- bcc (Optional[Union[str, List[str]]]): BCC recipient email address(es).
- include_attachments (bool): Whether to include original attachments. Defaults to True. Only includes real attachments, not inline images.
create_email_draft
- to (Union[str, List[str]]): Recipient email address(es).
- subject (str): Email subject.
- body (str): Email body content.
- cc (Optional[Union[str, List[str]]]): CC recipient email address(es).
- bcc (Optional[Union[str, List[str]]]): BCC recipient email address(es).
- attachments (Optional[List[str]]): List of file paths to attach.
- is_html (bool): Whether the body is HTML format. Set to True when sending formatted emails with HTML tags (e.g., bold, links, images). Use False (default) for plain text emails.
send_draft
- draft_id (str): The unique identifier of the draft to send. To get a draft ID, first use list_drafts() to list drafts, or use the ‘draft_id’ returned from create_email_draft().
fetch_emails
- query (str): Gmail search query string. Use Gmail’s search syntax: - ‘from:[email protected]’ - emails from specific sender - ‘subject:meeting’ - emails with specific subject text - ‘has:attachment’ - emails with attachments - ‘is:unread’ - unread emails - ‘in:sent’ - emails in sent folder - ‘after:2024/01/01 before:2024/12/31’ - date range
fetch_thread_by_id
- thread_id (str): The unique identifier of the thread to fetch. To get a thread ID, first use list_threads() to list threads, or use the ‘thread_id’ returned from send_email() or reply_to_email().
modify_email_labels
- message_id (str): The unique identifier of the message to modify. To get a message ID, first use fetch_emails() to list messages, or use the ‘message_id’ returned from send_email() or create_email_draft().
- add_labels (Optional[List[str]]): List of label IDs to add to the message. Label IDs can be: - System labels: ‘INBOX’, ‘STARRED’, ‘IMPORTANT’, ‘UNREAD’, etc. - Custom label IDs: Retrieved from list_gmail_labels() method.
move_to_trash
- message_id (str): The unique identifier of the message to move to trash. To get a message ID, first use fetch_emails() to list messages, or use the ‘message_id’ returned from send_email() or create_email_draft().
get_attachment
- message_id (str): The unique identifier of the message containing the attachment. To get a message ID, first use fetch_emails() to list messages, or use the ‘message_id’ returned from send_email() or create_email_draft().
- attachment_id (str): The unique identifier of the attachment to download. To get an attachment ID, first use fetch_emails() to get message details, then look for ‘attachment_id’ in the ‘attachments’ list of each message.
- save_path (Optional[str]): Local file path where the attachment should be saved. If provided, the attachment will be saved to this location and the response will include a success message. If not provided, the attachment data will be returned as base64-encoded content in the response.
list_threads
- query (str): Gmail search query string. Use Gmail’s search syntax: - ‘from:[email protected]’ - threads from specific sender - ‘subject:meeting’ - threads with specific subject text - ‘has:attachment’ - threads with attachments - ‘is:unread’ - unread threads - ‘in:sent’ - threads in sent folder - ‘after:2024/01/01 before:2024/12/31’ - date range
list_drafts
- max_results (int): Maximum number of drafts to fetch.
- page_token (Optional[str]): Pagination token from a previous response. If provided, fetches the next page of results.
list_gmail_labels
create_label
- name (str): The name of the label to create.
- label_list_visibility (str): How the label appears in Gmail’s label list. - ‘labelShow’: Label is visible in the label list sidebar (default) - ‘labelHide’: Label is hidden from the label list sidebar
- message_list_visibility (str): How the label appears in message lists. - ‘show’: Label is visible on messages in inbox/lists (default) - ‘hide’: Label is hidden from message displays
delete_label
- label_id (str): The unique identifier of the user-created label to delete. To get a label ID, first use list_gmail_labels() to list all labels. Note: System labels (e.g., ‘INBOX’, ‘SENT’, ‘DRAFT’, ‘SPAM’, ‘TRASH’, ‘UNREAD’, ‘STARRED’, ‘IMPORTANT’, ‘CATEGORY_PERSONAL’, etc.) cannot be deleted.
modify_thread_labels
- thread_id (str): The unique identifier of the thread to modify. To get a thread ID, first use list_threads() to list threads, or use the ‘thread_id’ returned from send_email() or reply_to_email().
- add_labels (Optional[List[str]]): List of label IDs to add to all messages in the thread. Label IDs can be: - System labels: ‘INBOX’, ‘STARRED’, ‘IMPORTANT’, ‘UNREAD’, etc. - Custom label IDs: Retrieved from list_gmail_labels().
get_profile
get_contacts
- max_results (int): Maximum number of contacts to fetch.
- page_token (Optional[str]): Pagination token from a previous response. If provided, fetches the next page of results.
search_people
- query (str): Search query for people in contacts. Can search by: - Name: ‘John Smith’ or partial names like ‘John’ - Email: ‘[email protected]’ - Organization: ‘Google’ or ‘Acme Corp’ - Phone number: ‘+1234567890’
_get_gmail_service
_get_people_service
_authenticate
_create_message
_get_message_details
_get_header_value
_extract_message_body
- message (Dict[str, Any]): The Gmail message dictionary containing the payload to extract text from.
_extract_attachments
- message (Dict[str, Any]): The Gmail message dictionary containing the payload to extract attachments from.
- attachment_id: Gmail’s unique identifier for the attachment
- filename: Name of the attached file
- mime_type: MIME type of the attachment
- size: Size of the attachment in bytes
- is_inline: Whether this is an inline image (embedded in HTML)
_is_valid_email
- Plain email: [email protected]
- Named email: John Doe
<[email protected]>