Hi, welcome back.
And this video, we will learn how to create the business email list, Python script or program, it
could be that far from your code.
So you can utilize from the ideas and the concepts.
Firstly, we will import as empty b leape.
As from as MTV left and bought as MTV in our case, as we learned in the last video then and the next
step, we went and bought Banda's module, which will make us able to read data from X.
L.
S X, which is an Excel file that contains our business email list.
So we will use the comment and board Banda's as beardie then in the next step to invert.
Appleton by some module called Day Time, which which we don't need to install it to our bison's revulsion
using Rapsody, so we will imported the rectally as the following import day time.
Now let's jump in sublime text editor to apply these steps by doing and complete our code as a following.
So after we open sublime text editor new file and save it as Benice email list by, we will ensure that
the bell system is bison and sent texts from the View dropdown is bison then type from.
As MTV left inboard s m TV in the other case, as we learned in the last video, then import Banda's
as BD, then the last step in importing the needed by some Majles is to import the time.
Now we will declare four variables that we will use in our code as the following.
The first variable is called password with a capital equal between two single codes or double codes.
The password of the sender email account.
So we assign the password to the password, the e-mail account password that we use to send emails to
that email list, and the second variable is called Sender.
Which is the sender e-mail account between two or equal between two single codes or double codes, demotic
academy and Gmail dot com, that the e-mail I will use to send emails to the email list.
The third variable is called now.
The set variable called Now, which express the actual time now and do we need a false variable called
actual time to use the object of the now variable?
They time they time it now inside it to get the following.
So actual time or actual date equal.
So we create an object express or use the day time, the time dot now to express Z, the actual time
now and use it in the next or fourth variable called the actual date equal between two parentheses as
as a table.
Now the day and now that month, so we will get that day and the months of the actual date now.
Throws this variable actual date.
Now we will use Banda's to read the Excel file that contains the customer names and customer emails.
So emails under score lists variable equal.
We did not read Excel between two parentheses and two single or double quotes, e-mail, underscore
list or e-mails underscore is not ex.
L.
S X five.
Which is the Excel file extension, so to use binders to read from Excel, we will use binders or board
dot read Excel method, which will take the name and extension of the file or the director of the file
of you use another vison idea rather than sublime text, which will work in the working directory if
the file isn't in the working directory.
You saw at the file directory before the file name and the file extension between two.
Single cause or double quotes inside the parentheses of the methods of Reid underscore Excel of module,
then assign the names inside the Excel sheet to variables called names and emails as the following.
So names equal emails underscore lists between two.
Square brackets, name with.
Capital N as an Excel file.
The name is.
The name of the column.
And the emails is the names of the column of the emails.
So emails equal.
Email.
Underscore less between two square brackets, email, not email.
Email, not emails, I will fix this error later, then we will use the MTV lab to connect the servers
of the Zemel using the hostname for the Gmail, which is as MTV Gmail dot com and also using Port Ekwall
five hundred eighty seven to avoid connection errors.
So connect server equals.
As MTV in our case.
Between two parentheses.
And to saying accord's.
As MTV.
Dot dot com, which is the hosts and the world is five hundred eighty seven, the next step is.
That we will use that as protocol to encrypt our e-mail, to avoid and to make it impossible for anyone
to read that mail except the recipients or the receiver emails.
So connect to underscore server dot Assad GLW methods will do that.
Then we will use login Massood to log in the sender emails to use that and sending emails to email lists
as the following connect underscore server dot log in between two parentheses sender and password variables
that we declared and assigned to a value in the first part of this code.
Then to send the email to more than one email or two emails in the Excel sheet we use for Loop to iterate
through the emails and the names in the spreadsheet, add the following using range and length functions.
For.
Item, a range between two parentheses Len, and between two parentheses of Len function or length function
email.
Which means that for every record that she'd get the name and email address, so inside the loop we
will add a name equal.
Names between two square brackets.
Idam.
Made equal emails between square brackets item, then we will use Claw's method to close the connection
as we learned last video connects underscores dot close method.
The last step of closing the connection to the server is one of the best practices that make our code
fast, clean and concise.
But we can add with a method instead of closing the server after every connection.
So we will open the server during the ending process, only using weather as the following.
So we will remove.
The Connect underscores server close method first, then, and with Massood as a following, I will
remove the variable connect, underscore server equality or assignment, then remove the closed method
of the server or connect to underscore server dot close mitzel, then add ways before assumptive method
which contains the host and the word as connect underscore server column.
Then make the rest of code follow the intention of with method.
Now our code is ready to send emails, but we need to add send email method as the following.
But before adds the send email method, we will add the control flow f statement to control the sending
of the email date as the following.
So if actual underscore that doesn't equal, which is a volume comparison between two parentheses twenty
and eleven, so twenty four days and eleven for months.
And inside the statement we will add the message that we want to be sent.
So a message equal between two single codes or double codes.
Subject.
With a Capital s column, Black Friday discounts.
Offers a new line, new line high and Tukur brackets and don't wait and buy now and close.
The double.
Godes.
Double code is more appropriate now than single codes in this statement or message.
Why?
Because we use d'Hondt which a single code.
Then connect underscore server dots and e-mail between two parentheses sender, comma, between two
square brackets, e-mail, comma, message, close the parentheses of the.
So we will use the sender and the list of emails and the message we want to be sent.
And we will use L.F. to repeat this code another two times, one time for White Friday for all the other
time for so L.F. actual time.
Underscore that equal, equal or equal between two.
Prentice's.
Any.
And coma and toile.
And the message will be message equal.
And instead of White Friday.
And instead of right there in the first message will be Black Friday.
And in December will be the White Friday.
That is the correct for November and December, then we will add another for.
Testing only and we will remove it and the end of the project, if we need or if we wish at the following,
so L.F. actual date, that will equal between two prentice's.
The date of that of today to test the email.
To be sent to our e-mail list that we specified in our code.
So.
The date of today is five of December.
Collum message as.
Equal.
White Friday also.
And send mail and we can.
Test it now.
But we can also add.
Branch statements to so we will add in the cell the message good is OK and add another brand statement
as a following and cancel the White Friday.
Then add a statement.
Inside that between two volunteers is testing, testing result is OK and another brand statement and
the addition of the old coot or the general in the identity of the good brand between two branches is
all done.
Full stop.
Between two parentheses.
And run our good.
We can run our good.
By clicking on Tool's.
Drop down them, BHEL.
To build or run the code now, we will add the comments to our crew to be more clean and more understandable
and also dog strength to the functions or Zidan station inside loops as the following.
For every action we take, we will add the comment for it as a following.
As you see, I write a command for every action.
That I take in the court and every block of code, I add my.
Comment to make other people understand my.
Now we can build our project and run it as the following tools and build to run our project, and we
get an error because of we at wrong names as a name is not divine.
Why name is not defined.
We will correct emails to Emmies.
Firstly, sorry, I forget to add the names of the column of the Excel sheet inside to single or double
quotes.
So I will do that and I will run the code again to.
And wait for the logic to run, it ran successfully, but it returned one message only it should return
three message and no email and Yahoo mail or have been sent to Yahoo mail.
This error is because of the EFF and Ayliffe statements are outside the fold.
So we will adjust this intention for the EFF and if statements to be inside the follow as the following
by marking the block of code, then click on Tell This and Move It for Space's.
Which side interation in the python, according to a now we will try to build and run our project again,
which will run successfully and we will get three message.
And all is done message.
This means that the same emails are sent and received by the email list.
Now we can check our emails that we are sent to the email list by checking one of the email and the
email list, the following, which is Yahoo!
Main.
So after checking Yahoo!
Email.
Account.
We see that our men have been sent, but there is an error, which is the email has no name, high calorie
bracket code is OK.
So we have here subject.
And message, but without the name of the customers, we can fix this issue as the following, using
four main function at DOT for me between two parentheses name, which is the main function of the string
or the string format function and python, you can refer or receive it in the first.
Part of this course, so not for me to name between two parentheses will solve this issue and run this
project or build this project again, tools them well to run this project, we can maximize the good
area by using view slide bar.
Hide slimeballs, then we can run our project now.
After we run and build our project, we get three messages, as it should be, and we kind of shake
now our Yahoo mail.
The subject.
It's OK, discount offer and the message, hi, customer to code is OK.
As we specified in the Excel sheet, the name is Customer two and the e-mail team will take Academi
at Yahoo!
Dot com.
At this point, we reach the end of this lecture and the end of this project.
Thank you for being here and thanks for watching.
See you next section.