Retrieving emails with IMAP clients, hi, guys, were already, as you can see in the terminal because
they were going to use the IMAP protocol in order to retrieve some messages.
First of all, again, I want to show you here in the emails.
So in your Gmail, in SEO settings, select this field.
And if you don't enable the email, please select forward to pop.
I'm up and then go down and enable that I'm up, as you can see here, OK, and enable all of those
options.
But you will usually be there automatically once you select enable IMAP, because if you don't do anything,
this button will be selected to disabled IMAP.
OK, so I just want to do this because if you don't do it otherwise, our code will not work because
obviously to use IMAP on your Gmail you need to have it enabled.
OK.
Set up here are in our terminal and I will actually open the pie chart here and I will create a new
file there so we can implement some functions.
So the first file that we are going to create, let's create a new python file.
And here I will write folder in full.
OK, so here, here the file, guys.
But before writing, let's go to a terminal, because you need to make sure that you have installed
the I am up protocol.
OK, you can definitely do that with the pipe.
So right.
Pipe install and then I up client.
OK, so install this and you can see that I already have this package, but for you it might take some
time to install was don't have it yet.
So then let's go back to the pie chart and let's start writing.
So let's write here.
User slash bean slash N.V..
OK, and then let's write Python three, OK.
And then I'll write from I am up client import IMAP client.
OK, so this will be our class from which we are going to create a map object.
OK, so after that let's also import the get sorry.
Get past.
OK, and this will be used for us to create a secure password.
The first thing to do is to ask the user to create his username and password like we always did.
So let's try it.
User name equals input, ok, input and then enter your user name.
OK, and after that let's write password in here.
I will do get pass that get passed and here and said let's write prompt equals.
And the prompt is basically what the user will see before writing his password.
So the prompt will be enter your password.
OK, let's add some space here.
Actually I will do it without space because you are not going to see your password anyways.
Let's try this now.
Server, SQL Server.
And here here is how we'll be connecting to the server actually mixed in the space here a bit.
So here, when you write a server, let's write, I'm a client, OK?
And then I map that Gmail dot com, OK.
And then comma SSL equals two through OK.
And after that let's log into the server.
So let's write server dot login.
So let me do that in the first line here, we're basically creating a variable that is a type I'm up.
So here we simply connect to the server and pass all the server credits to the server here.
And in the next line we're going to connect to our email on this server by writing our username and
password so you don't need any other things there.
Now, let's write a variable select info.
And here we're going to write one line with which we're going to get the info from our mailbox.
So we'll write a server dot select.
Folder, comma, and then they write in box to get the mail from the inbox, read only so will not be
able to update and they will right through.
OK, so this is how we read our mail.
And then let's write for K and V in list and then select info dot items.
So for each item in this list we would like to print it.
So let's print it.
This is basically we're going to print information from our mailbox so percent s and then percent are
OK.
And here in the brackets I will write K and V, which are the parameters that we're going to print.
And now finally, we need to close the connection.
So let's write server thought.
Log out, log out and that's it.
So we are ready.
So since are really guys, I saved the file and let's go back here to the terminal and let's write aways
and you can see that we already have the folder in full file right here.
So let's write Python and then folder in full and now we will need to enter your username.
OK, and then the password.
OK, so now we're connecting to my mailbox and you can see that this was quite fast and you can get
all the information from the folders in my mailbox, something that definitely you cannot do with the
proper protocol.
And you can see that there are existing one hundred and twenty one emails we are getting here, the
answer to the flag, the drafts, the deleted scene, not phishing and phishing emails.
So basically you are getting all the information for your email that you need.
So we don't have a recent email.
We have the text in the the validity and so on.
So here is how you can basically get the information for your email quite easily using the IMAP protocol.
Now, all this if I was working, let's actually create one more file and the next file will be called
mailbox listing.
So let's create new python file and this will be called mailbox listing.
And we're going to see all the capabilities that our Gmail can do with the IMAP using this file.
So let's try it here again.
Let me get closer and let's right now user slash bin slash Ian fee and then Python three.
OK, and then let's import OK, import prices.
And then from a map client.
I am of Klamt import.
I am map client.
OK, so we have them up client here enabled.
And of course I'm going to import the guest password toolkit so we can add the password and you can
do the same thing.
Let's write user name equals input and then they input it will be enter your username.
OK, and after that I will write password equals get pass and here I will write dots and get pass in
the brackets.
Let's write prompt equals to enter your password.
OK, next list are other server as the same as we did last time, so server will be equal to IMAP client
and in the brackets let's write IMAP dots and Gmail dot com.
So in that way we're connecting to the Gmail and then SSL equals two through.
OK, and then we're going to try here a statement.
So we're going to fight server dot login username and password.
So we're creating a triangle here guys, because we want to be sure that we assess the email correctly.
And if not, we would like to display the proper error.
So if we don't, we don't assess it in the correct way, with one exception here and this will be server
dot error us e and on this will print could not walk in.
OK, and then Colma e so this method will be added to the error and then sis dot exit and exit with
one or whatever.
Now since we are ready with that, let's print and let's provide some user friendly information here.
So let's print capabilities.
OK, and here I will write Colma server dot capabilities.
OK then let's print another thing.
So here I will print listing mailbox.
OK and then let's write.
The data will be equal to server dot list underscore folders.
OK, so here we have some list of our folders and then I will write for Flock's Delamater and folder
name in data and the for the list folders is giving all this information.
That way we can freely provide it here and here we are going to print percent minus 30 s percent s and
then percent s and then here we are going to display the following.
So empty space dot and join a string flux.
OK.
Then comma the meter and then folder name.
OK, that's it.
So once we're ready here, guys, you can close the server.
So server dot logout and we're ready here.
So this was a bit of a struggle, the last lines.
But if you want somebody to look in a nice way, you need to a little bit more of a struggle.
But basically, this is just the design is not what we are here about.
Right.
So if you don't understand fully the last line, don't worry, the main functionality is way above it.
So let's save that file here and let's go to the terminal.
So let's write a list here.
And as you can see, guys, you can see the mailbox listing file.
So let's write Python and then mailbox listing and now simply provide your username and your password.
OK, so once you do that, you can see this funny looking message, but you can see here his children
in box, which means that we have some folders over there and you can see basically wishfulness have
children or folders or emails inside and which do not.
And you can see basically the different types of folder like trash start spam sent mail important and
so on.
So all these folders that are already created in your Gmail guys are basically, um, there simply because
of the IMAP protocol and it enables your emails to build automatically stored in this type of folders.
And above that you can see the capabilities which are the different ideas and functions that you can
basically do with the emails in your mailboxes.
So this is the way that you can use a map in order to display the folders, guys.
And that's, I think, very much for watching this video and actually this section, because it's the
last course in the last video in this section.
Thanks for watching that section, guys.
And I will see you in our next adventure.