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 ID of the message to reply to (found in send_email/list_drafts results or users.messages.get).
- 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 ID of the message to forward (found in send_email/list_drafts results or users.messages.get).
- to (Union[str, List[str]]): Recipient email address(es).
- forward_body (Optional[str]): Additional message to include.
- 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 ID of the draft to send.
fetch_emails
- query (str): Gmail search query string.
- max_results (int): Maximum number of emails to fetch.
- include_spam_trash (bool): Whether to include spam and trash.
- label_ids (Optional[List[str]]): List of label IDs to filter emails by. Only emails with ALL of the specified labels will be returned. Label IDs can be: - System labels: ‘INBOX’, ‘SENT’, ‘DRAFT’, ‘SPAM’, ‘TRASH’, ‘UNREAD’, ‘STARRED’, ‘IMPORTANT’, ‘CATEGORY_PERSONAL’, etc. - Custom label IDs: Retrieved from list_gmail_labels() method.
- page_token (Optional[str]): Pagination token from a previous response. If provided, fetches the next page of results.
fetch_thread_by_id
- thread_id (str): The ID of the thread to fetch.
modify_email_labels
- message_id (str): The ID of the message to modify (found in send_email/list_drafts results or users.messages.get).
- 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 ID of the message to move to trash (found in send_email/list_drafts results or users.messages.get).
get_attachment
- message_id (str): The ID of the message containing the attachment (found in send_email/list_drafts results or users.messages.get).
- attachment_id (str): The ID of the attachment.
- save_path (Optional[str]): Path to save the attachment file.
list_threads
- query (str): Gmail search query string.
- max_results (int): Maximum number of threads to fetch.
- include_spam_trash (bool): Whether to include spam and trash.
- label_ids (Optional[List[str]]): List of label IDs to filter threads by. Only threads with ALL of the specified labels will be returned. Label IDs can be: - System labels: ‘INBOX’, ‘SENT’, ‘DRAFT’, ‘SPAM’, ‘TRASH’, ‘UNREAD’, ‘STARRED’, ‘IMPORTANT’, ‘CATEGORY_PERSONAL’, etc. - Custom label IDs: Retrieved from list_gmail_labels() method.
- page_token (Optional[str]): Pagination token from a previous response. If provided, fetches the next page of results.
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): Label visibility in label list.
- message_list_visibility (str): Label visibility in message list.
delete_label
- label_id (str): The ID of the user-created label to delete. Retrieve the label ID from
list_gmail_labels().
modify_thread_labels
- thread_id (str): The ID of the thread to modify.
- 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.
- max_results (int): Maximum number of results to fetch.
_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: john@example.com
- Named email: John Doe
<john@example.com>