Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: Concept: Sending an email with SendGrid
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
There are a lot of little details about sending an email a send grid, but in reality it's actually really,
0:06
really simple. So what we're gonna do is start by building out the HTML, and we were able to leverage the Jinja template engine to do that.
0:13
We'll see more about that later, but we just call this build HTML _function,
0:16
give it the template and then the details dictionary that provides the data. To that jinja template. Then we create a send grid client.
0:24
We just set the API key. And remember, we did that by storing our secrets secretly and not putting them into
0:30
source control, knowing created from email, a to email on the subject as object oriented
0:35
things out of send grid. So from class, to class and a subject class generate the HTML content. We converted the HTML to plain text using HTML2text
0:45
Then we created a male object with our From, To, Subject and all that information and finally just called client.send got a response.
0:53
If the response code or status code was 200 201 or 202, most likely, everything was good. Otherwise, something bad has happened.
1:02
We're not really sure what, but something bad. So we're going to raise an exception. Say sorry. Couldn't send that email.
1:09
That's it. And remember, we sent beautiful HTML emails that looked great and professional
1:14
by having this actual HTML generated having the static files back on our site that we could reference to you and so on, came out really good.