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 with a few little replacement pieces of text in here is incredibly easy in Python.
0:14 So, here is a fragment from the email template I use when you purchase a course from me at Talk Python Training.
0:22 So I need to send you things like how do you get back to the course you just bought, how much did you pay for it, what date was it purchased on,
0:29 what was your email, how did you pay, things like that. So, you can imagine the rest of the formatting that you already saw,
0:35 stick this right in the middle and that is pretty much what you get. So I'll use a dictionary with the course URL fragment set, the course price,
0:44 already formatted, I typically format that to a string in Python and send it over like 69.00 or just 69, however you want it to appear,
0:53 so you don't rely on the string, sort of string representation of whatever it is you pass across.
1:01 Similarly with the purchase date text, I'll actually create a string exactly the way I'd like it to look, in Python and then just pass that,
1:09 ultimately that string in the dictionary and so on. So this is really easy, how do we load this up and actually send it?
1:16 This method sort of combines two of the things we did, it's a little harder to use but if we want to get a template from a file
1:23 so we'd pass in the HTML file name in a replacement dictionary, and we'll just read the text in, not all emails are going to have a replacement,
1:32 like maybe you are going to send "hey, thanks for signing up" and that is the same for everybody, you don't have to pass like some dictionary,
1:38 you can just send, just return the HTML. But if we do have a replacement dictionary, we are going to use my little curly syntax {some text name}
1:48 and we'll just do a replace, straight up string replace on all the keys in the dictionaries with their various values and return it.
1:55 And that is it, you are sending HTML email out of files that you can manage separately
2:01 that are not in code, that are not in a database, that are very simple for people who are not programmers or just want to use design tools
2:07 like HTML editors on it.


Talk Python's Mastodon Michael Kennedy's Mastodon