Gmail API Reference

Complete reference for all Gmail service methods and properties.

Gmail Class

python
from gspace import GSpace

gspace = GSpace.from_oauth(credentials_file, scopes=["gmail"])
gmail = gspace.gmail()

Methods

send_simple_email

Send a simple text email.

python
def send_simple_email(
    to: str | list[str],
    subject: str,
    body: str,
    cc: str | list[str] | None = None,
    bcc: str | list[str] | None = None
) -> dict

Parameters:

  • to (str | list[str]): Recipient email address(es)
  • subject (str): Email subject
  • body (str): Email body text
  • cc (str | list[str], optional): CC recipients
  • bcc (str | list[str], optional): BCC recipients

Returns: Sent message dictionary

send_email

Send an email with attachments and advanced options.

python
def send_email(
    to: str | list[str],
    subject: str,
    body: str,
    attachments: list[str] | None = None,
    cc: str | list[str] | None = None,
    bcc: str | list[str] | None = None,
    html_body: str | None = None
) -> dict

get_message

Get a specific message by ID.

python
def get_message(message_id: str) -> dict

list_messages

List messages from the mailbox.

python
def list_messages(
    query: str | None = None,
    max_results: int = 10,
    page_token: str | None = None
) -> list[dict]

search_messages

Search for messages using Gmail search syntax.

python
def search_messages(
    query: str,
    max_results: int = 10
) -> list[dict]

delete_message

Delete a message.

python
def delete_message(message_id: str) -> None

list_labels

List all labels.

python
def list_labels() -> list[dict]

create_label

Create a new label.

python
def create_label(
    name: str,
    label_list_visibility: str = "labelShow"
) -> dict

add_label

Add a label to a message.

python
def add_label(message_id: str, label_id: str) -> dict

remove_label

Remove a label from a message.

python
def remove_label(message_id: str, label_id: str) -> dict

create_draft

Create a draft message.

python
def create_draft(
    to: str | list[str],
    subject: str,
    body: str
) -> dict

send_draft

Send a draft message.

python
def send_draft(draft_id: str) -> dict