pyopticon.utilities.gmail_helper module
- class pyopticon.utilities.gmail_helper.GmailHelper(gmail_address, auth_string, destination_emails)
Bases:
objectThis widget allows your Python code to send emails and, by extension, texts. It’s mainly useful for sending notifications after an interlock is tripped, e.g. if the dashboard detects that an instrument went offline partway through an automation script.
You’ll need to follow an online tutorial to get an ‘app password’ for a gmail account to allow Python to send emails from that account. You can test that it worked by constructing a GmailHelper object in a shell like IDLE and trying to send yourself emails from it. If you’d like to send texts, send an email to the appropriate address at the cell carrier’s SMS gateway, e.g. xxx-xxx-xxxx@vtext.com for Verizon.
- Parameters:
gmail_address (str) – The gmail address from which you want the notification to be sent.
auth_string (str) – An app password (or equivalent) for the gmail account.
destination_emails (str) – A list of the email addresses to which you want to send the notifications.
- send_email(subject, message_body)
Send an email with the specified subject and message to the email addresses specified when this GmailHelper was created.
- Parameters:
subject (str) – The subject of the email. Note that if you’re using this to send texts through an SMS gateway, different carriers treat the subject in different ways.
message_body (str) – The body text of the email message to send.