1
00:00:00,450 --> 00:00:02,110
Hi, welcome back.

2
00:00:02,880 --> 00:00:11,980
And this video, we will learn how to create the business email list, Python script or program, it

3
00:00:12,000 --> 00:00:13,770
could be that far from your code.

4
00:00:14,010 --> 00:00:19,760
So you can utilize from the ideas and the concepts.

5
00:00:20,620 --> 00:00:26,130
Firstly, we will import as empty b leape.

6
00:00:27,410 --> 00:00:40,220
As from as MTV left and bought as MTV in our case, as we learned in the last video then and the next

7
00:00:40,220 --> 00:00:48,260
step, we went and bought Banda's module, which will make us able to read data from X.

8
00:00:48,260 --> 00:00:48,680
L.

9
00:00:48,710 --> 00:00:58,880
S X, which is an Excel file that contains our business email list.

10
00:01:00,560 --> 00:01:10,310
So we will use the comment and board Banda's as beardie then in the next step to invert.

11
00:01:11,850 --> 00:01:22,620
Appleton by some module called Day Time, which which we don't need to install it to our bison's revulsion

12
00:01:22,630 --> 00:01:31,140
using Rapsody, so we will imported the rectally as the following import day time.

13
00:01:31,710 --> 00:01:42,420
Now let's jump in sublime text editor to apply these steps by doing and complete our code as a following.

14
00:01:43,020 --> 00:01:54,750
So after we open sublime text editor new file and save it as Benice email list by, we will ensure that

15
00:01:54,750 --> 00:02:05,040
the bell system is bison and sent texts from the View dropdown is bison then type from.

16
00:02:06,130 --> 00:02:18,400
As MTV left inboard s m TV in the other case, as we learned in the last video, then import Banda's

17
00:02:18,400 --> 00:02:29,600
as BD, then the last step in importing the needed by some Majles is to import the time.

18
00:02:29,880 --> 00:02:36,000
Now we will declare four variables that we will use in our code as the following.

19
00:02:36,370 --> 00:02:44,170
The first variable is called password with a capital equal between two single codes or double codes.

20
00:02:45,250 --> 00:02:49,030
The password of the sender email account.

21
00:02:50,520 --> 00:03:00,780
So we assign the password to the password, the e-mail account password that we use to send emails to

22
00:03:00,780 --> 00:03:05,940
that email list, and the second variable is called Sender.

23
00:03:06,940 --> 00:03:17,760
Which is the sender e-mail account between two or equal between two single codes or double codes, demotic

24
00:03:17,830 --> 00:03:26,410
academy and Gmail dot com, that the e-mail I will use to send emails to the email list.

25
00:03:27,910 --> 00:03:30,580
The third variable is called now.

26
00:03:31,590 --> 00:03:43,260
The set variable called Now, which express the actual time now and do we need a false variable called

27
00:03:43,260 --> 00:03:49,980
actual time to use the object of the now variable?

28
00:03:50,980 --> 00:03:56,560
They time they time it now inside it to get the following.

29
00:03:57,070 --> 00:04:02,220
So actual time or actual date equal.

30
00:04:02,830 --> 00:04:12,460
So we create an object express or use the day time, the time dot now to express Z, the actual time

31
00:04:12,460 --> 00:04:22,840
now and use it in the next or fourth variable called the actual date equal between two parentheses as

32
00:04:22,840 --> 00:04:24,250
as a table.

33
00:04:25,470 --> 00:04:33,480
Now the day and now that month, so we will get that day and the months of the actual date now.

34
00:04:35,260 --> 00:04:38,170
Throws this variable actual date.

35
00:04:38,460 --> 00:04:49,420
Now we will use Banda's to read the Excel file that contains the customer names and customer emails.

36
00:04:49,420 --> 00:04:56,740
So emails under score lists variable equal.

37
00:04:57,770 --> 00:05:06,980
We did not read Excel between two parentheses and two single or double quotes, e-mail, underscore

38
00:05:06,980 --> 00:05:11,120
list or e-mails underscore is not ex.

39
00:05:13,200 --> 00:05:13,590
L.

40
00:05:13,650 --> 00:05:15,930
S X five.

41
00:05:18,100 --> 00:05:27,160
Which is the Excel file extension, so to use binders to read from Excel, we will use binders or board

42
00:05:27,700 --> 00:05:37,750
dot read Excel method, which will take the name and extension of the file or the director of the file

43
00:05:37,750 --> 00:05:48,970
of you use another vison idea rather than sublime text, which will work in the working directory if

44
00:05:48,970 --> 00:05:51,730
the file isn't in the working directory.

45
00:05:52,030 --> 00:05:59,650
You saw at the file directory before the file name and the file extension between two.

46
00:06:00,570 --> 00:06:09,420
Single cause or double quotes inside the parentheses of the methods of Reid underscore Excel of module,

47
00:06:09,780 --> 00:06:21,200
then assign the names inside the Excel sheet to variables called names and emails as the following.

48
00:06:21,390 --> 00:06:27,360
So names equal emails underscore lists between two.

49
00:06:29,560 --> 00:06:32,290
Square brackets, name with.

50
00:06:33,820 --> 00:06:36,450
Capital N as an Excel file.

51
00:06:37,590 --> 00:06:38,580
The name is.

52
00:06:40,750 --> 00:06:41,950
The name of the column.

53
00:06:43,430 --> 00:06:46,900
And the emails is the names of the column of the emails.

54
00:06:47,840 --> 00:06:50,150
So emails equal.

55
00:06:51,300 --> 00:06:51,990
Email.

56
00:06:54,670 --> 00:07:00,010
Underscore less between two square brackets, email, not email.

57
00:07:04,690 --> 00:07:15,010
Email, not emails, I will fix this error later, then we will use the MTV lab to connect the servers

58
00:07:15,370 --> 00:07:27,220
of the Zemel using the hostname for the Gmail, which is as MTV Gmail dot com and also using Port Ekwall

59
00:07:27,790 --> 00:07:32,550
five hundred eighty seven to avoid connection errors.

60
00:07:32,860 --> 00:07:36,430
So connect server equals.

61
00:07:38,020 --> 00:07:40,840
As MTV in our case.

62
00:07:42,860 --> 00:07:44,990
Between two parentheses.

63
00:07:46,980 --> 00:07:48,540
And to saying accord's.

64
00:07:49,360 --> 00:07:50,620
As MTV.

65
00:07:53,840 --> 00:08:03,470
Dot dot com, which is the hosts and the world is five hundred eighty seven, the next step is.

66
00:08:04,510 --> 00:08:16,690
That we will use that as protocol to encrypt our e-mail, to avoid and to make it impossible for anyone

67
00:08:16,690 --> 00:08:23,850
to read that mail except the recipients or the receiver emails.

68
00:08:25,240 --> 00:08:32,410
So connect to underscore server dot Assad GLW methods will do that.

69
00:08:32,710 --> 00:08:43,910
Then we will use login Massood to log in the sender emails to use that and sending emails to email lists

70
00:08:44,800 --> 00:08:55,030
as the following connect underscore server dot log in between two parentheses sender and password variables

71
00:08:55,030 --> 00:09:02,830
that we declared and assigned to a value in the first part of this code.

72
00:09:04,670 --> 00:09:15,830
Then to send the email to more than one email or two emails in the Excel sheet we use for Loop to iterate

73
00:09:15,830 --> 00:09:25,820
through the emails and the names in the spreadsheet, add the following using range and length functions.

74
00:09:28,640 --> 00:09:29,240
For.

75
00:09:31,330 --> 00:09:44,200
Item, a range between two parentheses Len, and between two parentheses of Len function or length function

76
00:09:44,590 --> 00:09:45,340
email.

77
00:09:46,790 --> 00:09:55,640
Which means that for every record that she'd get the name and email address, so inside the loop we

78
00:09:55,640 --> 00:09:57,980
will add a name equal.

79
00:09:59,790 --> 00:10:03,420
Names between two square brackets.

80
00:10:04,580 --> 00:10:05,270
Idam.

81
00:10:06,450 --> 00:10:16,800
Made equal emails between square brackets item, then we will use Claw's method to close the connection

82
00:10:16,830 --> 00:10:23,840
as we learned last video connects underscores dot close method.

83
00:10:24,030 --> 00:10:32,100
The last step of closing the connection to the server is one of the best practices that make our code

84
00:10:32,100 --> 00:10:34,980
fast, clean and concise.

85
00:10:35,340 --> 00:10:44,150
But we can add with a method instead of closing the server after every connection.

86
00:10:45,090 --> 00:10:53,750
So we will open the server during the ending process, only using weather as the following.

87
00:10:54,150 --> 00:10:55,740
So we will remove.

88
00:10:58,140 --> 00:11:09,000
The Connect underscores server close method first, then, and with Massood as a following, I will

89
00:11:09,000 --> 00:11:17,730
remove the variable connect, underscore server equality or assignment, then remove the closed method

90
00:11:17,820 --> 00:11:26,250
of the server or connect to underscore server dot close mitzel, then add ways before assumptive method

91
00:11:26,400 --> 00:11:32,070
which contains the host and the word as connect underscore server column.

92
00:11:32,340 --> 00:11:38,040
Then make the rest of code follow the intention of with method.

93
00:11:38,160 --> 00:11:46,500
Now our code is ready to send emails, but we need to add send email method as the following.

94
00:11:46,500 --> 00:11:55,320
But before adds the send email method, we will add the control flow f statement to control the sending

95
00:11:55,320 --> 00:11:58,390
of the email date as the following.

96
00:11:58,410 --> 00:12:08,670
So if actual underscore that doesn't equal, which is a volume comparison between two parentheses twenty

97
00:12:09,000 --> 00:12:14,460
and eleven, so twenty four days and eleven for months.

98
00:12:15,120 --> 00:12:22,250
And inside the statement we will add the message that we want to be sent.

99
00:12:22,980 --> 00:12:29,700
So a message equal between two single codes or double codes.

100
00:12:31,380 --> 00:12:32,220
Subject.

101
00:12:33,540 --> 00:12:39,330
With a Capital s column, Black Friday discounts.

102
00:12:40,230 --> 00:12:50,580
Offers a new line, new line high and Tukur brackets and don't wait and buy now and close.

103
00:12:52,430 --> 00:12:53,210
The double.

104
00:12:54,580 --> 00:12:55,180
Godes.

105
00:12:58,270 --> 00:13:06,830
Double code is more appropriate now than single codes in this statement or message.

106
00:13:07,720 --> 00:13:08,290
Why?

107
00:13:09,550 --> 00:13:15,220
Because we use d'Hondt which a single code.

108
00:13:16,500 --> 00:13:25,050
Then connect underscore server dots and e-mail between two parentheses sender, comma, between two

109
00:13:25,200 --> 00:13:30,840
square brackets, e-mail, comma, message, close the parentheses of the.

110
00:13:31,140 --> 00:13:39,240
So we will use the sender and the list of emails and the message we want to be sent.

111
00:13:39,360 --> 00:13:50,130
And we will use L.F. to repeat this code another two times, one time for White Friday for all the other

112
00:13:50,130 --> 00:13:54,960
time for so L.F. actual time.

113
00:13:56,620 --> 00:14:03,520
Underscore that equal, equal or equal between two.

114
00:14:05,690 --> 00:14:06,620
Prentice's.

115
00:14:09,440 --> 00:14:09,800
Any.

116
00:14:10,810 --> 00:14:13,270
And coma and toile.

117
00:14:15,720 --> 00:14:18,720
And the message will be message equal.

118
00:14:20,920 --> 00:14:23,080
And instead of White Friday.

119
00:14:24,040 --> 00:14:28,960
And instead of right there in the first message will be Black Friday.

120
00:14:30,370 --> 00:14:33,730
And in December will be the White Friday.

121
00:14:35,670 --> 00:14:43,830
That is the correct for November and December, then we will add another for.

122
00:14:44,820 --> 00:14:55,470
Testing only and we will remove it and the end of the project, if we need or if we wish at the following,

123
00:14:56,130 --> 00:15:02,550
so L.F. actual date, that will equal between two prentice's.

124
00:15:04,200 --> 00:15:08,850
The date of that of today to test the email.

125
00:15:10,280 --> 00:15:18,140
To be sent to our e-mail list that we specified in our code.

126
00:15:19,770 --> 00:15:20,190
So.

127
00:15:21,820 --> 00:15:25,930
The date of today is five of December.

128
00:15:27,880 --> 00:15:30,550
Collum message as.

129
00:15:31,380 --> 00:15:31,980
Equal.

130
00:15:33,520 --> 00:15:35,050
White Friday also.

131
00:15:36,360 --> 00:15:40,590
And send mail and we can.

132
00:15:42,070 --> 00:15:43,270
Test it now.

133
00:15:44,970 --> 00:15:46,980
But we can also add.

134
00:15:47,990 --> 00:15:59,750
Branch statements to so we will add in the cell the message good is OK and add another brand statement

135
00:15:59,900 --> 00:16:03,800
as a following and cancel the White Friday.

136
00:16:05,080 --> 00:16:07,060
Then add a statement.

137
00:16:08,730 --> 00:16:17,280
Inside that between two volunteers is testing, testing result is OK and another brand statement and

138
00:16:17,280 --> 00:16:25,920
the addition of the old coot or the general in the identity of the good brand between two branches is

139
00:16:25,920 --> 00:16:26,670
all done.

140
00:16:27,000 --> 00:16:27,720
Full stop.

141
00:16:29,260 --> 00:16:30,730
Between two parentheses.

142
00:16:31,650 --> 00:16:33,960
And run our good.

143
00:16:35,570 --> 00:16:37,070
We can run our good.

144
00:16:38,440 --> 00:16:40,180
By clicking on Tool's.

145
00:16:41,040 --> 00:16:42,570
Drop down them, BHEL.

146
00:16:43,930 --> 00:16:53,550
To build or run the code now, we will add the comments to our crew to be more clean and more understandable

147
00:16:54,340 --> 00:17:05,050
and also dog strength to the functions or Zidan station inside loops as the following.

148
00:17:05,710 --> 00:17:12,030
For every action we take, we will add the comment for it as a following.

149
00:17:12,400 --> 00:17:16,840
As you see, I write a command for every action.

150
00:17:18,570 --> 00:17:24,630
That I take in the court and every block of code, I add my.

151
00:17:26,170 --> 00:17:31,120
Comment to make other people understand my.

152
00:17:31,960 --> 00:17:39,550
Now we can build our project and run it as the following tools and build to run our project, and we

153
00:17:39,550 --> 00:17:47,440
get an error because of we at wrong names as a name is not divine.

154
00:17:47,680 --> 00:17:49,420
Why name is not defined.

155
00:17:49,660 --> 00:17:52,170
We will correct emails to Emmies.

156
00:17:52,170 --> 00:18:03,490
Firstly, sorry, I forget to add the names of the column of the Excel sheet inside to single or double

157
00:18:03,490 --> 00:18:04,140
quotes.

158
00:18:04,150 --> 00:18:11,130
So I will do that and I will run the code again to.

159
00:18:12,130 --> 00:18:23,470
And wait for the logic to run, it ran successfully, but it returned one message only it should return

160
00:18:23,500 --> 00:18:31,810
three message and no email and Yahoo mail or have been sent to Yahoo mail.

161
00:18:32,530 --> 00:18:40,000
This error is because of the EFF and Ayliffe statements are outside the fold.

162
00:18:40,210 --> 00:18:51,220
So we will adjust this intention for the EFF and if statements to be inside the follow as the following

163
00:18:51,520 --> 00:18:59,440
by marking the block of code, then click on Tell This and Move It for Space's.

164
00:19:00,330 --> 00:19:11,580
Which side interation in the python, according to a now we will try to build and run our project again,

165
00:19:12,150 --> 00:19:17,580
which will run successfully and we will get three message.

166
00:19:18,690 --> 00:19:21,300
And all is done message.

167
00:19:22,200 --> 00:19:30,330
This means that the same emails are sent and received by the email list.

168
00:19:30,630 --> 00:19:40,860
Now we can check our emails that we are sent to the email list by checking one of the email and the

169
00:19:40,860 --> 00:19:44,520
email list, the following, which is Yahoo!

170
00:19:44,520 --> 00:19:44,870
Main.

171
00:19:45,600 --> 00:19:48,120
So after checking Yahoo!

172
00:19:48,120 --> 00:19:48,750
Email.

173
00:19:49,780 --> 00:19:50,590
Account.

174
00:19:51,680 --> 00:20:04,880
We see that our men have been sent, but there is an error, which is the email has no name, high calorie

175
00:20:04,880 --> 00:20:07,240
bracket code is OK.

176
00:20:08,060 --> 00:20:10,850
So we have here subject.

177
00:20:11,750 --> 00:20:21,440
And message, but without the name of the customers, we can fix this issue as the following, using

178
00:20:21,440 --> 00:20:30,040
four main function at DOT for me between two parentheses name, which is the main function of the string

179
00:20:30,320 --> 00:20:39,380
or the string format function and python, you can refer or receive it in the first.

180
00:20:40,100 --> 00:20:50,240
Part of this course, so not for me to name between two parentheses will solve this issue and run this

181
00:20:50,780 --> 00:21:00,860
project or build this project again, tools them well to run this project, we can maximize the good

182
00:21:00,920 --> 00:21:04,190
area by using view slide bar.

183
00:21:05,140 --> 00:21:10,960
Hide slimeballs, then we can run our project now.

184
00:21:12,100 --> 00:21:22,660
After we run and build our project, we get three messages, as it should be, and we kind of shake

185
00:21:22,660 --> 00:21:24,580
now our Yahoo mail.

186
00:21:26,060 --> 00:21:27,050
The subject.

187
00:21:27,970 --> 00:21:34,210
It's OK, discount offer and the message, hi, customer to code is OK.

188
00:21:35,310 --> 00:21:43,950
As we specified in the Excel sheet, the name is Customer two and the e-mail team will take Academi

189
00:21:44,220 --> 00:21:45,210
at Yahoo!

190
00:21:45,210 --> 00:21:45,750
Dot com.

191
00:21:46,980 --> 00:21:52,910
At this point, we reach the end of this lecture and the end of this project.

192
00:21:53,580 --> 00:21:57,150
Thank you for being here and thanks for watching.

193
00:21:57,330 --> 00:21:59,640
See you next section.
