Skip to content

Instantly share code, notes, and snippets.

@thinkingserious
Created January 28, 2016 17:03
Show Gist options
  • Save thinkingserious/27902b119fb3454db418 to your computer and use it in GitHub Desktop.
Save thinkingserious/27902b119fb3454db418 to your computer and use it in GitHub Desktop.
Improve deliverability by including both a text and HTML email body
import sendgrid
from bs4 import BeautifulSoup
def send_email(self, to_email, from_email, subject, body):
message = sendgrid.Mail()
message.add_to(to_email)
message.set_subject(subject)
soup = BeautifulSoup(body, "html.parser")
message.set_text(soup.get_text())
message.set_html(body)
message.set_from(from_email)
status, msg = self.sg.send(message)
return status, msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment