Created
January 28, 2016 17:03
-
-
Save thinkingserious/27902b119fb3454db418 to your computer and use it in GitHub Desktop.
Improve deliverability by including both a text and HTML email body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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