Message class
This is the full description of the Message class.
- class google_workspace.gmail.message.Message
A full message. This message is returned for “raw” and “full” message formats.
- Parameters
gmail_client (
GmailClient
) – The gmail_client.message_data (
dict
) – The raw message data.
- in_reply_to
The message id of the message this message replies to.
- references
The message ids of the messages this message is a reply to.
- is_reply
Whether the message is a reply or not.
- message_id
A string of the the message id.
- subject
A string of the message subject.
- raw_from
A string of the message’s From header which can be used when sending messages to include the name.
- raw_to
A list of the message’s To header in it’s original form.
- raw_cc
A list of the message’s Cc header in it’s original form.
- raw_bcc
A list of the message’s Bcc header in it’s original form.
- to
A list of the message’s To header with the email addresses only.
- cc
A list of the message’s Cc header with the email addresses only.
- bcc
A list of the message’s Bcc header with the email addresses only.
- raw_from_name
A string of the from name, potentially encoded.
- from_
A string of the email address of the sender.
- from_name
A string with the senders name decoded.
- raw_date
A string of the message date in it’s original form.
- date
A Datetime object with the message’s date.
- is_bulk
A boolean set to True when the message has the Precedence header set to bulk.
- text
A string with the message’s plain text body.
- html
A string with the message’s html body.
- attachments
A list of
Attachment
objects.
- html_text
A string of the text extracted from the html body.
- has_attachments
A boolean indicating if the message has real attachments.
- gmail_client
The gmail client.
- message_data
The raw message data from the API.
- gmail_id
The message id used for the API.
- thread_id
The messgae thread ID.
- label_ids
A list of labels.
- snippet
A short snippet from the message.
- is_seen
Whether the message is marked as read or not.
- is_chat_message
If this message is a chat message.
- add_labels(label_ids: Union[list, str]) dict
Add labels to this message.
- Parameters
label_ids (
list
|str
) – The lables to add.- Returns
The API response.
- Return type
dict
- delete() dict
Delete this message permanently.
- Returns
The API response.
- Return type
dict
- forward(to: Optional[Union[list, str]] = None, cc: Optional[Union[list, str]] = None, bcc: Optional[Union[list, str]] = None, headers: Optional[dict] = None) dict
Forward this message.
- Parameters
to (
list
|str
, optional) – Who to send the message to. Can be either a string or a list of strings. Defaults to None.cc (
list
|str
, optional) – The cc recipients. Defaults to None.bcc (
list
|str
, optional) – The bcc recipients. Defaults to None.headers (
dict
, optional) – Additional headers to add to the message. Defaults to None.
- Returns
The API response.
- Return type
dict
- classmethod from_full_format(gmail_client: google_workspace.gmail.gmail.GmailClient, message_data: dict)
Create a message from the “full” format.
- Parameters
gmail_client (
GmailClient
) – The gmail_client.message_data (
dict
) – The raw message data in “full” format.
- get_header(header: str) Optional[str]
Get a header from this message.
- Parameters
header (
str
) – The header name.- Returns
If the header was found this will return the header value, otherwise it will return None.
- Return type
str
| None
-
get_thread(message_format: Optional[Literal[
'minimal','full','metadata']] = None) google_workspace.gmail.thread.Thread Get the message’s full thread.
- Parameters
message_format (
str
, optional) – In which format to retrieve the messages. Can have one of the following values:"minimal"
,"full"
,"metadata"
. If this is not set we default to the format of the current message. Defaults to None.- Returns
The full thread.
- Return type
- mark_read() dict
Mark this message as read.
- Returns
The API response.
- Return type
dict
- mark_unread() dict
Mark this message as unread.
- Returns
The API response.
- Return type
dict
- remove_labels(label_ids: Union[list, str]) dict
Remove labels from this message.
- Parameters
label_ids (
list
|str
) – The lables to remove.- Returns
The API response.
- Return type
dict
- reply(text: Optional[str] = None, html: Optional[str] = None, attachments: Union[Iterable[str], Iterable[Tuple[bytes, str]]] = [], headers: Optional[dict] = None) dict
Reply to this message.
- Parameters
text (
str
, optional) – The plain text of the message. if you only specifyhtml
the text will be automaticly generated. Defaults to None.html (
str
, optional) – The html of the message. Defaults to None.attachments (
list
, optional) – A List of attachments. Can be a list of file paths like this [“image.png”, “doc.pdf”], or it can be a list of lists where every list consists of the attachment data and a name for the attachment like this [[b”some binary here”, “image.png”]]. Defaults to [].headers (
dict
, optional) – Additional headers to add to the message. Defaults to None.
- Returns
The API response.
- Return type
dict
- trash() dict
Move this message to the trash.
- Returns
The API response.
- Return type
dict
- untrash() dict
Untrash this message.
- Returns
The API response.
- Return type
dict