From 2d86d548a37c3adbeb723792e5988060b2c65139 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Wed, 17 Nov 2021 19:59:27 +0200 Subject: [PATCH] update sendgrid code --- webapp/utils.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/webapp/utils.py b/webapp/utils.py index b535e97..c311eba 100644 --- a/webapp/utils.py +++ b/webapp/utils.py @@ -59,20 +59,28 @@ def send_email(to, subject, body, html=False): logging.debug(f"body: {body}") return - from_email = Email(DEFAULT_EMAIL_FROM_ADDR) - to_email = To(to) - sub = Subject(subject) + from_email = DEFAULT_EMAIL_FROM_ADDR + to_email = to + sub = subject + html_content = None + plain_text_content = None if (html): - content = HtmlContent(body) + html_content = HtmlContent(body) else: - content = PlainTextContent(body) + plain_text_content = PlainTextContent(body) - mail = Mail(from_email, to_email, sub, content) + mail = Mail( + from_email=from_email, + to_emails=to_email, + subject=sub, + html_content=html_content, + plain_text_content=plain_text_content + ) try: sg = sendgrid.SendGridAPIClient(EMAIL_API_KEY) - response = sg.client.mail.send.post(request_body=mail.get()) + response = sg.send(mail) if response.status_code != 202: raise Exception(f'Failed to send email: {response.body}')