Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Add docstring to function send_email.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfir committed Mar 31, 2021
1 parent 9b87fd8 commit d25efba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mail_error_notifs/mail_error_notifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,28 @@


def send_email(subject, mailbody):
"""Sends an email using Sendgrid's service to one or more recipients.
FROM and TO addresses and SENDGRID_API_KEY need to be available as environment variables.
Positional arguments:
subject -- A string with the subject of the email.
mailbody -- A string with the body of the email. Content type will be text/plain.
"""
try:
sg = SendGridAPIClient(os.getenv('SENDGRID_API_KEY'))
from_email = From(os.getenv('FROM'), 'Chronos Maybelambda')
to_emails = To(os.getenv('TO'))
subject = Subject(subject)
content = PlainTextContent(mailbody)
mail = Mail(from_email, to_emails, subject, content)

response = sg.send(mail)
print('SendGrid response status code:', response.status_code)
print('SendGrid response body:', response.body)
except Exception as e:
logging.error(e)


if __name__ == '__main__':
load_dotenv('./.env')
logging.basicConfig(
Expand Down

0 comments on commit d25efba

Please sign in to comment.