snoozingmail package

Module contents

snoozingmail is a python3 wrapper around the gmail api.

The ‘Snoozin’ object is the primary interface to the api. To perform actions further than the methods in the Snoozin object, you can utilize the creds, modify, read and send modules for more granular access to the gmail api.

class snoozingmail.Snoozin(credentials)[source]

Interface into the gmail api wrapper.

Has methods to read, send, and modify messages in the connected gmail account.

__init__(credentials)[source]

Initialize the Snoozin object by creating the gmail service using the provided credentials file.

Parameters:credentials – Local path to credentials file
add_msg_labels(msg_id, labels)[source]

Add labels to the given message.

Parameters:
  • msg_id – The id of the message, which can be used to get details of the message.
  • labels – list of labels (ex: ‘[‘STARRED’, ‘UNREAD’]’ for starred unread emails)
get_labeled_msgs(labels)[source]

Get message ids for messages that have all the given labels

Parameters:labels – list of labels (ex: ‘[‘STARRED’, ‘UNREAD’]’ for starred unread emails)
Returns:List of message ids
get_matching_msgs(query)[source]

Get message ids for messages that match the given query

Parameters:query – String used to filter messages returned. (ex: ‘from:user@some_domain.com’ for Messages from a particular sender.)
Returns:List of message ids
get_msg_body(msg_id)[source]

Get the plain text portion of the given message’s body.

Parameters:msg_id – The id of the message, which can be used to get details of the message.
Returns:The plaintext message body if it exists. Otherwise, None.
get_sender(msg_id)[source]

Get the sender of the given message.

Parameters:msg_id – The id of the message, which can be used to get details of the message.
Returns:The sender’s email address with name ommitted.
remove_msg_labels(msg_id, labels)[source]

Remove labels from the given message.

Parameters:
  • msg_id – The id of the message, which can be used to get details of the message.
  • labels – list of labels (ex: ‘[‘STARRED’, ‘UNREAD’]’ for starred unread emails)
send(to, subject, message_body, html=False, attachments=[])[source]

Send a message.

Parameters:
  • to – Email address of the receiver.
  • subject – The subject of the email message.
  • plaintext_content – The plantext content of the email message.
  • message_text – The plaintext content of the email message.
  • html – (optional) Whether the mesage_body is formatted as html
  • attachments – (optional) List of file paths to files that should be attached to the email
Returns:

The message that was sent

Indices and tables