Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Beautiful confirmation emails
Lecture: Attaching the PDF to the email with SendGrid

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, we've made it farther. We've got one more of our TODO's done.
0:05 Very last thing to do here before we're completely finished with this section is attaching the
0:10 invoice through the email. But we're going to create like we did a To, and From and the Subject. We're gonna create a attachment.
0:22 I'm going to say a couple of things. Set the content, to be the encoded pdf
0:28 I set the disposition to attachment file type to application/pdf. Then finally, when they download it, let's go out and set.
0:41 The names will say attachment.file_name Cloud-City-invoice-{order.id}.pdf" That seems like a decent number.
0:51 So would be Cloud-City-invoice-18.pdf or whatever. And then the final thing we have to do is go and attach this to our
0:59 message. I go and say add an attachment, and we just say, Here's your attachment. I got some faith. Let's go and delete the studio.
1:10 I think we're going to be good. So we're going to your client, set up the email, set the email content. create the Pdf. Make it an attachment.
1:19 But if the email. Add the attachment and send it along. Let's bring it all together and see if this works, well. There was. That went pretty quick.
1:30 Time to check the email notice down here. You can see this is the output from pdf kit, by the way, about what it's doing.
1:36 So it looks like it generated the pdf. You look carefully. What's up here? Check this out. There's an attachment during the bottom.
1:44 It is Cloud-City-invoice-19. And there it is. Cloud City Cake Company. This is a Pdf. We could download it.
1:52 It's going to save exactly as the file name that we suggested. And there it is. We got our pdf attached to our fancy email that tells
2:03 everybody. Hey, thanks for ordering your cake. Keep your eye on your WhatsApp messages for when your cake is ready.
2:10 Fantastic. So you can see there are a couple of steps that we had to do that we're not entirely straight forward and obvious.
2:17 For example, building HTML out of the jinja template system and building the pdf using pdf kit. Neither of them are major,
2:26 And once you get these set up in your code, you can just use them and build out these emails in an incredibly simple way.
2:33 And of course, you have access to this code, so feel free to just copy it verbatim and use it in your projects.


Talk Python's Mastodon Michael Kennedy's Mastodon