Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Course conclusion and review
Lecture: Review: Sending an email with SendGrid

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When we received an order through WhatsApp and called into our API, we wanted to send a receipt to let the users know.
0:08 Here's your official receipt for purchasing our cake. So what we're gonna do is you send grid another Twilio service to send it.
0:16 So what we do is we create a dictionary that's going to allow us to pass data over to a Jinja template.
0:21 Remember, we could do all sorts of things to come up with that HTML. But a really flexible thing is suggest leverage Jinja to actually generate those.
0:30 And in order for Jinja to work, give it a dictionary of values and it can dynamically generate the HTML just like it
0:36 does in the Web itself. We got our HTML text will create the Send Grid API client. We pass over the API Key,
0:44 which were storing secretly. Remember that our secrets.json, we create 'from' 'to' and subject
0:50 object, passing over our information. The to is, following that
0:55 SQLAlchemy relationship. But our HTML content we're going to generate our text content by
1:01 just mark down file our HTML content and then we're gonna create our mail message with a sendgrid mail class. Just pass all the items over.
1:10 Go to the clients they send when you get a response. And as long as the response.status_code is 200, 201 or 202 we're all good. If it's something else,
1:18 we're gonna say there's an error and that's it. Incredibly simple to send a really nice email and in practice, remember, we also created an attachment,
1:27 pdf attachment, and we attached that as well. So really powerful email system here with Sendgrid.

Talk Python's Mastodon Michael Kennedy's Mastodon