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