update sendgrid code
This commit is contained in:
+15
-7
@@ -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}')
|
||||
|
||||
Reference in New Issue
Block a user