moe.mailer package

moe.mailer.gmailer module

The gmailer module contains a Mailer implementation based on Gmail.

class moe.mailer.gmailer.Gmailer(user, destination, secret='client_secret.json', credentials='credentials.json')[source]

Bases: object

Implementation of Mailer that leverages Gmail.

Capable of configuring existent gmail accounts for MOE to use. It does so through Gmail’s Label and a Filter capabilities.

Parameters:
  • user (str) – Email address of the user.
  • destination (str) – Email address of the other MOE user.
  • secret (str, optional) – Defaults to ‘client_secret.json’. File containing the OAuth 2.0 client ID of the MOE application.
  • credentials (str, optional) – Defaults to ‘credentials.json’. File containing the OAuth 2.0 Google user authentification.
Raises:
create_message(content, subject='MOE message')[source]

Creates a message object for an email.

It’s receiver its the configured receiver of Mailer. It’s sender is the configured user of Mailer.

Parameters:
  • content (str) – The subject of the email message.
  • subject (str, optional) – Defaults to DEFAULT_SUBJECT. The text of the email message.
Returns:

An object containing a base64url encoded email object.

Return type:

object

delete_message(message_id)[source]

Deletes a message from the inbox.

Parameters:message_id (str) – The id of the message to delete.
Return type:None
fetch_all()[source]

Fetch all the emails in MOE’s inbox.

Returns:A list with the MOE email dicts in chronological order.
Return type:List[Dict]
fetch_unread()[source]

Fetch all the emails in MOE’s inbox that are unread.

Returns:A list of MOE emails.
Return type:List[Dict]
mark_as_read(msg)[source]

Marks the email message as read from the MOE inbox in Gmail

If the message has already been read the function does not do anything.

Parameters:msg (Dict) – The MOE email to mark as read.
Returns:The updated MOE email.
Return type:Dict
read()[source]

Reads the latest unread message from the MOE inbox in Gmail.

If there is an unread email, the email is marked as seen, but not deleted. If there is no unread email, it returns an empty object.

Returns:MOE’s email object.
Return type:Dict
write(content)[source]

Sends an email with the content to the configured receiver.

This method ensures Gmailer is an implementation of the Writer interface.

Parameters:content (str) – The content to send.
Returns:The id of the sent message.
Return type:str