The Gmail connection and configuration, hi, everyone, today, as I promised, we're going to test
the poultry protocol and to do that first, I'm going to open a terminal.
So let's open the terminal and I will increase its size a bit, OK?
And also open by charm.
OK, so why would it opens?
I will go to my folder of preference that I want to execute the code.
And we're basically going to create a brand new script in which I'm going to show you how you can write,
create the file and then create the proper protocol and assess your email.
So once by charmeuse I will select the resources folder and now we're going here into the folder.
So in your resources folder, let's create Section six.
So let's create a new directory, Section six, or actually let's still write in Section five, as I
don't want to confuse you with new sections here.
And we only have two files.
So simply in Section five, I actually create the new python file in this file will be called pop mail.
OK, let's validate here and let's now write the code.
So first of all, I will of course, assess the python environment.
So I write hash tag, exclamation mark usera slash bean slash EMV, OK, and then Python three, OK,
and then let's import
pop library.
The code is the library we're actually going to use and then let's write mailbox equals pople library
dot pop three underscore SSL.
So you can see that here we're already using the popular SSL protocol and with this protocol we're going
to connect to the server and we connect to a server with the following way.
So let's write pop dot Gmail dot com comma nine nine five and then let's write mailbox dot user and
so inside the brickies here guys, you can write your username.
So my username, it's Pittaway, Yaniv Pittaway, Yaniv.
That's it.
And it automatically will at r at Gmail dot com.
So don't worry about that.
And after that you need to add your password so you can do this by mailbox.
OK, dot pass and here you are adding your password.
Of course I'm not going to add my password because you will be able to access my email and see all the
secret messages that are out there.
So I want privately, but here you can add your password and after that let's print mailbox dot get
welcome.
So we'll print some sort of welcome message so we can see it.
And after that I will write a for loop and then index.
So for index in range.
OK, and then let's right here message.
Yes.
OK.
Actually here we do not actually define the message so I will define it and the message is actually
a parameter which is going to be created from the mailbox parameter.
So I write message equals Lenn and then in the brackets mailbox.
So the parameters are already created, which is a top three protocol parameter that list.
And here let's write one.
So the first character in this list.
OK, that's it.
Our message.
And now this message is the same as here.
So it's past the for loop and then let's write and nested for loop.
So I write for here inside message in mailbox dot read through ok index.
That's right.
Plus one and then one here.
OK, so for this print message.
OK, that's it.
And then I will write here mailbox.
OK, actually removed his brackets because this thought, that's it.
OK, so we use the quick parameter on our mailbox.
OK, we're ready here.
So let's save this.
Don't forget, while your password go to a terminal and run this code.
So let's go, guys, into Section five.
OK, Airways.
And here you can see the pope may not be away.
So let's write Python Pulpmill the P way.
Let's run it in here.
You can see that the code actually run.
And what we're doing here, actually, we just received or retrieved all of the messages in my mailbox.
You can see how many they are there.
Quite a lot.
And actually, if I were to retrieve the messages from my other mailbox, there would be even more.
So basically here you get into an HTML file, just HTML file all the messages, the codes of all the
messages, how they're encrypted into my email.
OK, so you can see that here we connect it to the server and to the email so you can see deliver it
and then received by then you get the ports, the SMTP protocol and then you start receiving all the
mails here.
Obviously here from these things, you cannot understand basically absolutely anything.
You can just see different senders, different encryption messages and HTML code that is actually H.T.
a malicious code that's the same kwassa padding and how the email is basically positioned.
What is the budget of each different email that they have in my mailbox?
So obviously here, guys, there is not much that you can understand, but you can actually see how
you can get all the information for analysis from the email that you stated here and now.
Actually, I want to create another file which will actually ask the user to enter his credit.
Also, this will be way more dynamic file that can be used from anyone who has a Gmail that wants to
have his credit.
So I opened back up this picture ID and let's create the new file.
OK, and I will right here, Pop ask.
OK, so get a pop, ask people why file here.
And the idea of this file is to print only the new messages that we received on our email address.
So no other messages will be displayed except the new ones.
And let's try the file so I can show you how this is done.
So first of all, of course, we'll do the python initialization by user been E and V Python three,
OK, and then let's import pop library and then I'll import.
OK, I will import, get the pass and then let's create new value called mailbox.
OK, mailbox will be equal to pop library and dot pop three underscore SSL.
And here again we're going to assess the Gmail server.
So pop that Gmail dot com comma nine nine five and actually limit to one very important thing that I
probably missed and they didn't tell you.
It is very important before running all that code to establish connection with Gmail and that will show
how this is done.
So if I go now here to my Gmail and then go to see all settings, OK, here, you can configure your
Gmail and you can see actually we have four world and Pop IMAP, OK?
And here you are basically getting your options for Pope and for IMAP.
And although I think that your pope function is already created, then enabled here, you don't need
to do actually absolutely anything for the pope.
Don't vote.
But in general, the pope functionality, it's enabled.
But make sure that you have this option here.
Keep Gmail copy in the inbox.
OK, so this is fine.
And also you can configure the IMAP here.
So make sure that this option is to enabled out to exchange is also to enable and do not limit the number
of messages on my map is also enabled in the.
I'm up, we don't talk about it yet, but you will need it for the next lecture's because the next protocol
we're going to talk about and as you can see, Jhilmil perfectly predicts this type of protocols as
they're the most commonly used out there.
Now, once you know that, let's go back to the cold.
So, as I said here, we're getting on board nine, nine, five, and then under it, let's write user
name equals input.
And in the brackets, let's enter.
Enter your name or actually user name.
OK, and then let's create a password.
So password will be equal to get pass.
And we're doing that in a different way because obviously you don't want your password to be visible
on the screen while you're typing it.
So I will do get past pass and then let's write prompts to be equal.
And here is what method is going to be written to the user in order to get his password.
So I write Enter your password.
OK, and let's write a semicolon here.
That's it.
Now, once we have the parameters, we need it.
So we have our mailbox, we have the user name and we have the password.
Now we can use them in order to get the information from our email.
So let's do mail box dot user.
And here I write user name.
OK, and then mailbox dot pass underscore and then you can write the password.
OK, so here's how we pass the username and password to our mailbox which is located on Gmail dot com.
Right.
So while the creators are checked and accepted and we can continue, so let's do mail information.
OK.
And this will be quote to mailbox dot start.
OK, and this is how we started getting the information from our email.
OK, we're getting our email status.
And here I would like to print our message code number of new emails.
OK, and a layman right here, percent is in on the place of percent this list.
Right.
Email information, OK.
And then under it, the last number of mails and this will be called to email information is zero.
OK, because the mailbox does stopped.
So on the zero in that list, which means this is the first place we're basically getting the number
of unread emails.
OK.
OK, so that's good.
And this means that here we're going to print the number of the emails that are not read yet.
So the new emails.
But also I would like to display some of the information of those emails, not just a number.
So let's create here for Loop.
So for I in range and the range here will be the number of mails.
OK, actually instead let's create something different because I don't think that this would work.
Let's create another parameter which is called no messages.
OK, so a number of messages will be equal to Len Mailbox that list the brackets and then you say they
will write one.
OK, so we're going to take the first character from this list, which is going to be the number of
messages, and then we can actually pass the number messages here in order to assess the each of these
messages there.
OK, so let's say the number one you refer to measure one, then message to the military and so on.
So for each number, so for each message, basically, first of all, we're going to print.
OK, uh, let's do backslash N and I will write message
number.
OK.
Plus estar.
I plus one, so I plus one, because obviously the first message will be on the character zero, so
I would like to incremented with one for that reason, then let's print.
OK, so let's print some separation.
So I at some length here.
That's it.
And now, now is the time to actually read the message.
So let's hear it.
Response.
Cuomo.
Heather Lyons, KOMO Bites, and this will be equal to Mailbox Dot Retrieve.
I lost one.
OK, so here we are going to get the response to the hair and the bites, and this is because the dysfunction
here retrieve provides all of those in the role.
So the first of which is the response will be provided to the response variable, then the second to
the headlines and then to the bites.
OK, that's quite useful after that.
Let's do some prints.
So I would like to print some of the information from that message.
So I'll write print and then I'll write a message I.D., OK, and we're going to print the metadata
was located on the other lines which already obtained, and it is actually a list of lines.
So the idea is basically the first the first word in this list of lines.
Then let's print.
Date, OK, and here the date is usually located to the second character of the lines, then let's do
an hour print and the next print will be a reply to and here we are going to see the headlines in just
located in four.
So you can see that here, what we're basically doing.
So we're getting headlines basically contains all the data needed.
OK, but what we're doing here is simply presenting this data in better to read way.
I can obviously do print headlines and we are going to get all the information the same time.
But this is not the purpose here.
The purpose is to make something that is well presented to the user.
So it's easy to read and let's create the next line, which is the two.
OK, and here again, let's right here, the lines in this will be on position five, then I can print.
Subject.
OK.
Next is the subject, so let's do headlines again and then seven.
Actually, this one six sorry, six, then let's print again, and the next one will be my.
OK, let's write comma and again headlines, and this will be OK.
Now to the seventh element in that list.
And finally, let's print the last thing, which is the content type.
Content type.
OK, Cuomo headlines.
And this will be on the eighth location.
And once we're done, guys here, let's extend the for loop by going to the higher elevation level and
let's right mailbox dot quit.
So here is how we close the connection with the actual mailbox.
So once we're done with that, let's go a little bit up.
And I realized one typo here.
So we need to close the parenthesis before the nine nine five.
And you can see that now this is Mark in blue.
So we recognize the port.
Let's save now everything.
And I will go to a terminal and actually run the code with my Jhilmil Creditors'.
So if I go to the credit to the terminal sorry and I write hours, I can actually see all the files
here.
By the way, for use windows you need to write.
There are like this in order to see your directory, which here is not recognized.
But anyways, so here this is the Pope usque file.
So let's write python
underscore ask.
OK, let's run it.
So here you can see that the program is asking you to enter a username.
So mine is pure white Yanov, OK, and then it asks you for your password which is this one.
OK, and now you can see guys that we have the zero new messages.
And in fact this is the true I actually have exactly zero new messages.
So and if you go to my email actually and then go to my e-mail box.
Yes, you can see that I have some unread messages.
But the last one is from Google is a half hour ago.
So let me send the message to myself so I will do your way.
And if OK, subject.
Hello and then.
Hi, how are you.
This is a text message.
OK, so let's send this email and let's from here the again.
So Pittaway Yaniv at Gmail dot com or actually just pure Yanov will be enough.
And when I run these guys you can see that we are getting nearer and this might be a good thing because
this means that the code went forward.
So this plan got executed, which means that it understood.
We have no message, but now we would need to fix it.
So let's see, line twenty one here.
And yes, I can see that the parenthesis here are first of all, are not right, are not the right one.
OK, so we need this type of princess here.
Let's save it.
And I will read the code now once again.
So let's try it again.
OK, let's eliminate the password and you can see that now we're getting something very interesting.
So you are getting message number one, which means that we received two different messages and you
can see the message right here.
Also, you can see the date, which is basically the term of our code right here.
You can see that reply, that is from Plomin Yanov, which is actually the name of my father, which
also, um, helps me with developing the courses quite cool from him.
Then we can see the two, which is again the same email, because we sent an email to ourself.
Then we see the subject here.
You can see that we don't have time and you can see that the Condah types, again, some code, um,
that's obviously we cannot understand.
But the main thing we care about here is the reply and the two sections.
And also here you can see the date obviously can see that some of the fields a little bit messed up.
For example, here on the methods, you see the date and so on.
But that be due to the update of the versions of the pottery protocol.
So the right files might not be on the right places.
The most important for me is that the reply and the two are on the same places so we can see them.
Uh, but this means that everything was completely fine.
So that was everything I want to share with you about the protocol I.
This video was very useful for you and you had a lot of fun that's, I think, very much for watching.
Bear with me in the next videos where we're going to look at the IMF protocol and I will see you in
the next video.