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.
0:01 We've got one more of our TODO's done.
0:04 Very last thing to do here before we're completely finished with this section is attaching the
0:09 invoice through the email. But we're going to create like we did a To, and
0:14 From and the Subject. We're gonna create a attachment.
0:21 I'm going to say a couple of things.
0:24 Set the content, to be the encoded pdf
0:27 I set the disposition to attachment file type to application/pdf. Then finally,
0:39 when they download it, let's go out and set.
0:40 The names will say attachment.file_name Cloud-City-invoice-{}.pdf"
0:47 That seems like a decent number.
0:50 So would be Cloud-City-invoice-18.pdf or whatever.
0:54 And then the final thing we have to do is go and attach this to our
0:58 message. I go and say add an attachment,
1:02 and we just say, Here's your attachment.
1:06 I got some faith. Let's go and delete the studio.
1:09 I think we're going to be good.
1:10 So we're going to your client,
1:12 set up the email, set the email content.
1:15 create the Pdf. Make it an attachment.
1:18 But if the email. Add the attachment and send it along.
1:21 Let's bring it all together and see if this works, well.
1:27 There was. That went pretty quick.
1:29 Time to check the email notice down here.
1:31 You can see this is the output from pdf kit,
1:33 by the way, about what it's doing.
1:35 So it looks like it generated the pdf.
1:38 You look carefully. What's up here?
1:39 Check this out. There's an attachment during the bottom.
1:43 It is Cloud-City-invoice-19.
1:46 And there it is. Cloud City Cake Company.
1:47 This is a Pdf. We could download it.
1:51 It's going to save exactly as the file name that we suggested.
1:57 And there it is. We got our pdf attached to our fancy email that tells
2:02 everybody. Hey, thanks for ordering your cake.
2:05 Keep your eye on your WhatsApp messages for when your cake is ready.
2:09 Fantastic. So you can see there are a couple of steps that we had to
2:13 do that we're not entirely straight forward and obvious.
2:16 For example, building html out of the jinja template system and building the pdf using
2:22 pdf kit. Neither of them are major,
2:25 And once you get these set up in your code,
2:27 you can just use them and build out these emails in an incredibly simple way.
2:32 And of course, you have access to this code,
2:34 so feel free to just copy it verbatim and use it in your projects.