Python for Entrepreneurs Transcripts
Chapter: Sending and receiving email
Lecture: Concepts: Sending rich templated email

Login or purchase this course to watch this video and the rest of the course contents.
0:02 We've seen that sending templated emails that is a plain HTML file
0:07 with a few little replacement pieces of text in here is incredibly easy in Python.
0:13 So, here is a fragment from the email template I use
0:17 when you purchase a course from me at Talk Python Training.
0:21 So I need to send you things like how do you get back to the course you just bought,
0:25 how much did you pay for it, what date was it purchased on,
0:28 what was your email, how did you pay, things like that.
0:31 So, you can imagine the rest of the formatting that you already saw,
0:34 stick this right in the middle and that is pretty much what you get.
0:38 So I'll use a dictionary with the course URL fragment set, the course price,
0:43 already formatted, I typically format that to a string in Python
0:47 and send it over like 69.00 or just 69, however you want it to appear,
0:52 so you don't rely on the string,
0:57 sort of string representation of whatever it is you pass across.
1:00 Similarly with the purchase date text, I'll actually create a string
1:03 exactly the way I'd like it to look, in Python and then just pass that,
1:08 ultimately that string in the dictionary and so on.
1:11 So this is really easy, how do we load this up and actually send it?
1:15 This method sort of combines two of the things we did,
1:18 it's a little harder to use but if we want to get a template from a file
1:22 so we'd pass in the HTML file name in a replacement dictionary,
1:27 and we'll just read the text in, not all emails are going to have a replacement,
1:31 like maybe you are going to send "hey, thanks for signing up"
1:34 and that is the same for everybody, you don't have to pass like some dictionary,
1:37 you can just send, just return the HTML.
1:40 But if we do have a replacement dictionary, we are going to use
1:44 my little curly syntax {some text name}
1:47 and we'll just do a replace, straight up string replace on all the keys in the dictionaries
1:52 with their various values and return it.
1:54 And that is it, you are sending HTML email out of files that you can manage separately
2:00 that are not in code, that are not in a database, that are very simple for people
2:03 who are not programmers or just want to use design tools
2:06 like HTML editors on it.