Python for Entrepreneurs Transcripts
Chapter: Sending and receiving email
Lecture: Demo: Sending the welcome message (basic)
0:00 Remember back when we created the register method? We added this little bit said hey when we figure out to send email,
0:07 we are going to send an email here. So I want to go through two levels, I want to send a very basic email
0:12 just to show that sending emails is working and then we want to come back and we want to look it away to send very nice, beautiful emails
0:18 like I showed you in the beginning of this chapter. OK, so we are going to come here, we want to go email service,
0:24 and let PyCharm import that, thank you PyCharm and we want to call send_welcome_email, and we are going to need to say who we are sending it to,
0:34 remember, we don't actually get their name, we just have their email address, so we'll just send them an email say "hey you, welcome".
0:40 Alright, so PyCharm can write this function for us, like so, and it defaults to a class method, I am cool with that,
0:48 you can change it to static if you want or do something else, so what we are going to do is we are going to come up with the HTML_body,
0:55 and it's just going to be standard HTML. So let's do something like this. OK, so here is a pretty cheesy HTML email that we are going to use,
1:14 and let's just make this one, let's make this one strong so you can see some of the markdown stuff happening.
1:20 We are going to send this email and the way we are going to do it is we are just now going to call emails service, right? In email service,
1:27 we want to call that basic send_mail and we have to give the "to" address, which is email, subject is going to be "Welcome to Blue Yellow Rockets",
1:38 and the body is just going to be this HTML_body here. Right, that's all we got to do.
1:44 Now we are going to get much more advanced about constructing interesting stuff,
1:47 we are not going to write HTML like this much longer, but for a simple test, let's try this, we are going to run the site, and hopefully,
1:55 there is a lot of moving parts here, hopefully we got it right, so let's go over here and log out, and we are going to go register,
2:03 and I am going to try different account, I am going to do +blueyellow, it's a trick you can do on any Gmail address, is put a plus wherever you want
2:12 and it basically registers as a separate address, use the same password, it's very fancy, it's called test, so let's go.
2:20 Oh, it looks like it didn't quite work, so obviously, I forgot it was in dev mode,
2:26 so that is not going to send anything, and up here in this "register" we forgot to do out cookie_auth, remember we did our cookie_auth in "sign in"
2:34 but we didn't do it here, but the account was created, I have to create another one. Let's store the fact right away, let's do it almost immediately.
2:44 Store the cookie_auth, so here we are going to sign in, and we are going to send our welcome email,
2:49 and let's just go over here and put this not in dev mode. OK, I've actually set it to be not in dev mode,
2:56 what I have in my real apps over here is, I'll print this out, so let's go and do it here we'll say print('Running in ...such and such mode.
3:09 We'll say dev, dev mode, else prod. Try again, OK, so now you can see we are running a product mode, because I changed that,
3:23 let's register one more time, +blueyellow2 and back here for the sending, alright, registered, we just sent one live message, great,
3:37 now let's go checkout my email, you can see it took a second to do the email sending
3:42 and then it redirected, it didn't crash, that is already a good sign so let me go check my email and see what I've got.
3:48 Awesome, look what we've got here you guys, welcome to our site, I can see we have some sort of misspelling here, "Thanks for registering with use",
3:55 here is this, it should be "us", right? And I should probably put a new line in there, but that is not the point.
4:01 Look we sent, let me zoom this back a little, here we go, we sent our email to us, HTML email via Amazon SES,
4:11 it sent it to that address, how cool is that?