1 00:00:04,810 --> 00:00:09,040 External R.S.V.P. service, hello, everyone. 2 00:00:09,550 --> 00:00:10,420 Hello, everyone. 3 00:00:11,230 --> 00:00:18,400 Even though almost all of the Internet service providers are working with the same type of protocol, 4 00:00:18,400 --> 00:00:25,650 there are some quite huge benefits of working with them, external SMTP protocol. 5 00:00:26,320 --> 00:00:33,940 So you basically have better delivery of emails and you don't need to configure your own server like 6 00:00:33,940 --> 00:00:35,380 we actually did the last time. 7 00:00:35,380 --> 00:00:36,250 With the Gmail. 8 00:00:37,120 --> 00:00:44,370 So obvious to hear, you need to send the SMP server if you're working with Gmail, just would be Centipede 9 00:00:44,770 --> 00:00:46,330 Dota Gmail dot com. 10 00:00:47,680 --> 00:00:55,750 You need an SMP user, which is going to be you is going to be your Gmail account. 11 00:00:55,750 --> 00:01:03,280 Actually you need your Gmail password and also the S.A.T. report, which is usually the default port 12 00:01:04,210 --> 00:01:05,280 of a phone. 13 00:01:05,360 --> 00:01:13,050 Four hundred and sixty five and four TSL is going to be five hundred and eighty seven. 14 00:01:13,840 --> 00:01:21,250 So obviously here we're also going to use the Thai Airways, which is basically the security encryption 15 00:01:21,250 --> 00:01:21,880 protocol. 16 00:01:22,180 --> 00:01:33,220 But what is the good thing here is that you can simply enable Gmail to work with Python and send emails 17 00:01:33,220 --> 00:01:34,170 externally. 18 00:01:34,780 --> 00:01:43,510 So first of all, in order to enable that option for the Gmail to work with external service, you actually 19 00:01:43,510 --> 00:01:48,870 need to update your security settings directly inside your Gmail and how you can do that. 20 00:01:49,660 --> 00:01:59,920 So what you need to do is to simply go on my account dot Google dot com and then do slash less secure 21 00:01:59,950 --> 00:02:00,550 apps. 22 00:02:01,210 --> 00:02:07,270 OK, so once you go here, you can allow other apps to work with your Gmail. 23 00:02:07,510 --> 00:02:13,090 So just enable this option here and you can see that now is updated so you can use it. 24 00:02:13,270 --> 00:02:20,020 And once you update it now we can work with external apps and make them send emails from your Gmail. 25 00:02:20,290 --> 00:02:25,740 So now let's move to the terminal and I will show you a script that does this. 26 00:02:25,750 --> 00:02:32,110 So as we are here, guys, we can now proceed with actually sending email with Python. 27 00:02:32,320 --> 00:02:34,690 So lame, create a new file. 28 00:02:34,690 --> 00:02:42,520 So the new file and I would call the file exter now and Gmail. 29 00:02:42,700 --> 00:02:45,490 OK, let's hit OK here. 30 00:02:45,820 --> 00:02:52,480 And the file is now created and let's actually write, first of all, the steps that you would need 31 00:02:52,480 --> 00:02:54,790 in order to complete this project. 32 00:02:55,000 --> 00:03:07,210 So the first thing that we will need to do is to create a safety p object to connect to the server. 33 00:03:07,990 --> 00:03:09,830 OK, let me go a bit closer. 34 00:03:10,420 --> 00:03:13,600 So this will be the first step, then the second step. 35 00:03:14,200 --> 00:03:18,100 What we're going to do is to log into our accounts. 36 00:03:18,100 --> 00:03:22,160 So log in to account. 37 00:03:22,720 --> 00:03:39,970 OK, then step three here would be to define headers for the message and log in created those. 38 00:03:40,660 --> 00:03:56,560 OK, step for step four is going to be to create a eight, a mime multipart message object. 39 00:03:56,560 --> 00:04:04,690 And basically this object is going to attach to the header that we created earlier on. 40 00:04:05,410 --> 00:04:18,400 Then in step five, we're going to actually attach the message to the mime Muthee part. 41 00:04:20,460 --> 00:04:30,090 Object then in step six, which is going to be the final one, we send the message. 42 00:04:30,240 --> 00:04:34,050 OK, so we just heard all the steps, guys, that will fall in our cold. 43 00:04:34,260 --> 00:04:41,120 And now since we're aware of what we need to do in the cold, let's actually do the cold. 44 00:04:41,760 --> 00:04:57,150 So, as I said, the first thing we will do is from email dot mym dot muj part, import mym muj part. 45 00:04:57,310 --> 00:05:11,700 Then from email dot my dot text will import again my text so we can write our text. 46 00:05:11,940 --> 00:05:20,150 And finally, let's import s.m T.P Library and Werdum. 47 00:05:20,550 --> 00:05:25,480 So now as I said, the first step here is to create the SFP object. 48 00:05:26,010 --> 00:05:26,850 This is simple. 49 00:05:26,880 --> 00:05:33,390 Let's write message equals MYM Muj parts. 50 00:05:33,600 --> 00:05:36,370 OK, so our object is created. 51 00:05:36,370 --> 00:05:37,910 The images are the brackets here. 52 00:05:38,670 --> 00:05:44,850 Um then let's import import get pass class. 53 00:05:47,230 --> 00:05:49,630 And now the username and password. 54 00:05:49,660 --> 00:05:58,150 This time we're going to do a little bit differently because what they want to do is to enable the user 55 00:05:58,150 --> 00:06:02,080 that uses the code to type his email and password. 56 00:06:02,200 --> 00:06:04,810 OK, so they are not going to be predefined. 57 00:06:04,810 --> 00:06:11,290 And this right here, user name equals input. 58 00:06:12,280 --> 00:06:16,980 And then I will write you a user name, OK? 59 00:06:19,000 --> 00:06:24,280 And then for the password, I will do the same. 60 00:06:24,280 --> 00:06:31,180 So I will OK, let's for the password because who would not want to see the password in front of the 61 00:06:31,180 --> 00:06:31,570 screen. 62 00:06:31,570 --> 00:06:35,660 So you don't want the person that watches the screen to see your password. 63 00:06:35,680 --> 00:06:38,200 So there are some specific use for that reason. 64 00:06:38,860 --> 00:06:43,950 And this is the get passed method that we just imported here. 65 00:06:44,410 --> 00:07:03,470 So let's to get pass, not get pass and will do prompt equals and here our right password and that's 66 00:07:03,470 --> 00:07:03,650 it. 67 00:07:03,670 --> 00:07:09,280 Everything that you type after just keyword password is not going to be visible, but you actually type 68 00:07:09,280 --> 00:07:11,200 and validate your actual password. 69 00:07:11,710 --> 00:07:20,650 OK, so step two is completed and we or extra step three and we added our creditors and let's assume 70 00:07:20,650 --> 00:07:23,950 that you're already logged in from the browser. 71 00:07:24,340 --> 00:07:29,050 Now let's set the parameters here. 72 00:07:29,620 --> 00:07:35,470 So for the methods parameters, who are going to use the username, the password and actually the subject 73 00:07:35,470 --> 00:07:37,210 of all of our emails. 74 00:07:37,720 --> 00:07:43,750 So I will create first variable message that we created earlier on. 75 00:07:43,800 --> 00:07:47,980 OK, the message and I'm going to parse the different variable. 76 00:07:47,990 --> 00:07:57,080 So let's write from OK, so the sender is going to be equal to the user name. 77 00:07:57,800 --> 00:08:06,640 OK, so it will be the user name that we have here then the receiver for simplicity. 78 00:08:06,640 --> 00:08:10,990 I'm going to make the same email to send email to ourselves. 79 00:08:11,830 --> 00:08:14,770 OK, so I right here again, user name. 80 00:08:16,430 --> 00:08:30,810 And then message and here I right subject and here is the subject of the email sending email to myself. 81 00:08:31,610 --> 00:08:36,260 OK, so this is a subject and now we can add the message, board it. 82 00:08:36,740 --> 00:08:39,620 So the message board is very simple to add. 83 00:08:39,620 --> 00:08:46,880 You just typed message dot attach and then in the brackets will write my text. 84 00:08:46,910 --> 00:08:53,270 OK, because with the touch text in here, I will write a simple text. 85 00:08:54,860 --> 00:09:03,030 Hello, this is an e-mail from your self. 86 00:09:05,110 --> 00:09:07,600 To your self. 87 00:09:09,300 --> 00:09:11,660 It is fun, isn't it? 88 00:09:13,470 --> 00:09:17,400 OK, and then right, chroma plane. 89 00:09:19,320 --> 00:09:25,780 And you're ready with this land, so this will be the message that you're going to send to yourself. 90 00:09:26,430 --> 00:09:29,550 OK, now let's write a server. 91 00:09:31,090 --> 00:09:46,320 So server will be equal to SMPTE P library, OK, dot s empty P and here I will write the same P dot 92 00:09:47,190 --> 00:09:48,510 Gmail dot com. 93 00:09:49,030 --> 00:09:56,030 OK, so this is the server address and the port is going to be five eight seven. 94 00:09:56,280 --> 00:10:03,400 You can see that the server is a little bit different way comparing to our previous declaration here. 95 00:10:03,720 --> 00:10:10,470 So here we use the same type of library and latitude with comma, but in that case we still use the 96 00:10:10,470 --> 00:10:11,370 same type of library. 97 00:10:11,370 --> 00:10:14,090 But we just added it into a different way. 98 00:10:14,550 --> 00:10:18,450 Both ways obviously work so you can use either of them. 99 00:10:19,440 --> 00:10:27,990 And then Lizardo server dot start here with in this line here is simply for the encryption of our protocol. 100 00:10:28,260 --> 00:10:33,270 So the message gets encrypted and then decrypt it once it has been received. 101 00:10:34,960 --> 00:10:43,030 OK, so after we setup everything, we need to log in to our creditors in order to send the email right. 102 00:10:43,050 --> 00:10:44,630 We need to have access to our email. 103 00:10:45,000 --> 00:10:52,170 So since we already have our password and the email that are provided by the user of this script now, 104 00:10:52,170 --> 00:10:55,800 we would like to use them in order to be able to. 105 00:10:58,500 --> 00:11:02,580 Go inside your email, so I'll write a server. 106 00:11:04,140 --> 00:11:14,070 Not log in, OK, and here in the break, it's a right message and then from. 107 00:11:15,690 --> 00:11:18,810 OK, common password. 108 00:11:21,010 --> 00:11:27,280 Actually, his passport and I don't know why he is here, but I would definitely remove them. 109 00:11:27,910 --> 00:11:31,760 OK, so here is how, Logan. 110 00:11:32,500 --> 00:11:39,790 OK, so we definitely need to alter the password and the messages to the front person, which is equal 111 00:11:39,790 --> 00:11:44,380 to our username, which is the user name that the user provided here, OK. 112 00:11:44,710 --> 00:11:47,380 And then we use a password that's been provided as well. 113 00:11:47,830 --> 00:11:54,040 Now finally, after we stop everything we are loading, we set it up what the message is going to be 114 00:11:54,040 --> 00:11:54,610 and everything. 115 00:11:55,000 --> 00:11:57,710 Now it's time to simply send the message. 116 00:11:57,850 --> 00:12:02,110 So in the next three lines, I will write how you can send the message. 117 00:12:02,440 --> 00:12:05,700 So actually, you are doing this in one line. 118 00:12:06,190 --> 00:12:09,190 I will do server dot login. 119 00:12:11,060 --> 00:12:19,910 Actually, send the mail, OK, and then that's right, message and then from. 120 00:12:20,300 --> 00:12:27,590 OK, so this is the user would send the message from the message and then to. 121 00:12:29,480 --> 00:12:35,780 OK, so as you can see, first define the user within the message from then you define the user that 122 00:12:35,780 --> 00:12:36,910 was send the message to. 123 00:12:37,220 --> 00:12:41,350 And finally, you need to state the message that you're going to send. 124 00:12:41,810 --> 00:12:50,180 So the message you're going to send is a message which is of a type if you give me a chance, you or 125 00:12:50,180 --> 00:12:52,410 type my Muja part. 126 00:12:52,430 --> 00:12:59,160 OK, so this is your actual message to which you passed all the user names, the topic and so on. 127 00:12:59,450 --> 00:13:04,670 So this is the final product and you send it as a string. 128 00:13:04,850 --> 00:13:07,580 So as string. 129 00:13:07,910 --> 00:13:09,460 OK, here we go. 130 00:13:11,440 --> 00:13:15,970 And let's print then that we're successful. 131 00:13:16,000 --> 00:13:26,090 So if there are no errors, so we successfully send the email or sent to email and then we'll say to 132 00:13:26,090 --> 00:13:26,840 which email. 133 00:13:27,550 --> 00:13:34,150 So let's write percent is OK and write a percent. 134 00:13:34,150 --> 00:13:38,200 And then in the brackets, message two. 135 00:13:38,480 --> 00:13:44,650 OK, so the person that will receive the message would like to display that will send a message to him. 136 00:13:45,010 --> 00:13:53,540 And finally, let's exit the server so the server quit and that's it here. 137 00:13:54,010 --> 00:13:54,730 So we are ready. 138 00:13:54,760 --> 00:13:58,630 Guys, this is all the comments you need to add in order to send emails. 139 00:13:58,910 --> 00:14:04,480 You don't need to use any intention levels for a while, loops and whatsoever. 140 00:14:04,840 --> 00:14:08,740 You just need to know the comments and the posts you are sending the emails to. 141 00:14:09,130 --> 00:14:10,960 So let's save this. 142 00:14:11,440 --> 00:14:20,290 And I will go to a terminal now and let's write Elway's so you can see that here is the external Gmail. 143 00:14:20,590 --> 00:14:25,710 So let's do Python, Python and then external Gmail dot p way. 144 00:14:26,020 --> 00:14:26,680 Let's run it. 145 00:14:26,890 --> 00:14:29,770 And those that were asked for username. 146 00:14:29,770 --> 00:14:36,880 So my username is P White Yaniv at Gmail dot com. 147 00:14:37,240 --> 00:14:43,570 OK, and then the password I will type of course will not be able to see it and then we're getting on 148 00:14:43,570 --> 00:14:45,140 there probably a little typo. 149 00:14:45,160 --> 00:14:46,690 So let's see what it is. 150 00:14:48,040 --> 00:14:49,030 It is on line. 151 00:14:49,030 --> 00:14:53,200 Twenty three years so I can see the mistake is actually quite obvious. 152 00:14:53,500 --> 00:14:58,390 I don't ask here the parentheses so I will do it right now. 153 00:14:59,550 --> 00:15:01,740 OK, and let's try again. 154 00:15:02,560 --> 00:15:04,320 So I'll run the same thing. 155 00:15:04,600 --> 00:15:06,010 OK, and then. 156 00:15:08,450 --> 00:15:09,200 Let's run it. 157 00:15:11,400 --> 00:15:19,620 So you can see that here I get the message successfully sent to email PVA unfettered Gmail dot com, 158 00:15:19,860 --> 00:15:22,150 OK, which means that the email was sent. 159 00:15:22,470 --> 00:15:29,820 So let's try it once again and let me show you a picture, not a picture, but like my email from the 160 00:15:29,820 --> 00:15:36,630 browser so you can see if the email is actually being sent or not. 161 00:15:36,660 --> 00:15:40,680 OK, so this is my email and let's run the code once again. 162 00:15:41,550 --> 00:15:49,510 So I'll write a few way Yanov at Gmail dot com and then I'll type my password. 163 00:15:50,020 --> 00:15:53,480 OK, and let's see if the e-mail is going to be handed. 164 00:15:53,670 --> 00:16:01,950 I get the message successfully sent to email Piana at Gmail dot com and let's see if the message is 165 00:16:01,950 --> 00:16:03,600 actually going to be sent here. 166 00:16:04,350 --> 00:16:11,010 Let's reboot our email and you can see that in eight forty six pm my time like. 167 00:16:11,010 --> 00:16:14,370 So immediately after we send this you can see it's 846. 168 00:16:15,300 --> 00:16:16,810 The message has been sent. 169 00:16:17,280 --> 00:16:24,420 So if we open it you can see that the subject is sending email to myself, which is exactly which is 170 00:16:24,420 --> 00:16:26,850 exactly what we actually wrote in the cold here. 171 00:16:26,850 --> 00:16:27,960 Email to myself. 172 00:16:28,200 --> 00:16:31,250 And then the text inside is the one that was stated here. 173 00:16:31,620 --> 00:16:36,090 Hello, this is an email to yourself, from yourself to yourself. 174 00:16:37,050 --> 00:16:38,470 It is fun, isn't it? 175 00:16:39,540 --> 00:16:48,180 So this is how guys who are sending basically email from one email to another and with this type of 176 00:16:48,180 --> 00:16:51,600 protocol that they just displayed you, it is way easier. 177 00:16:51,600 --> 00:16:55,590 And it is actually my favorite to send automated emails. 178 00:16:55,770 --> 00:17:01,530 And you see how good control you have over the user who is sending the email and over the things you 179 00:17:01,530 --> 00:17:03,750 want to specify inside this email. 180 00:17:04,110 --> 00:17:06,810 So I hope you really had fun with this video. 181 00:17:07,830 --> 00:17:16,710 And this is going to be the end of the S empty P protocol and bear with me in the next videos in this 182 00:17:16,710 --> 00:17:22,620 section because we are going to talk about other email protocols and we are going to write a lot of 183 00:17:22,620 --> 00:17:23,610 phone calls. 184 00:17:23,610 --> 00:17:26,700 So we still have what you see here in this section. 185 00:17:27,000 --> 00:17:28,460 But that was for today. 186 00:17:28,680 --> 00:17:30,270 Thank you very much for watching, guys. 187 00:17:30,270 --> 00:17:32,430 And I will see you in the next video.