1
00:00:00,200 --> 00:00:01,160
Hey, welcome back.

2
00:00:01,160 --> 00:00:03,730
We have come a long way with this app.

3
00:00:03,740 --> 00:00:10,190
We were able to build the interface, get the data from the user, store them in the database, show

4
00:00:10,190 --> 00:00:12,050
a notification to the user.

5
00:00:12,080 --> 00:00:17,600
What's left to do now is to send a confirmation email to the user email address.

6
00:00:17,600 --> 00:00:24,500
So anything that the user enters here as an email address, we should send them an email using our own

7
00:00:24,500 --> 00:00:27,260
email address by our own.

8
00:00:27,260 --> 00:00:31,070
I mean something you want to use for this application.

9
00:00:31,070 --> 00:00:38,150
So perhaps not your personal email, but I do recommend to create a gmail account which you can use

10
00:00:38,150 --> 00:00:38,870
for this.

11
00:00:38,870 --> 00:00:45,050
So here I have one and the first thing you want to do in Gmail is you want to go to manage your Google

12
00:00:45,050 --> 00:00:51,980
account and you want to go to security and you need to turn on two step verification.

13
00:00:51,980 --> 00:00:59,450
If you haven't done that already, once you do that, you should go to app passwords again in security

14
00:00:59,450 --> 00:01:02,820
and you want to create a new app password here.

15
00:01:02,820 --> 00:01:11,970
So select other pick a name for this Flask application form, click on Generate and you want to copy

16
00:01:11,970 --> 00:01:12,750
that.

17
00:01:14,500 --> 00:01:19,090
That is the password of this Google account.

18
00:01:19,200 --> 00:01:20,410
App flask.

19
00:01:20,410 --> 00:01:25,380
So I'll be sending emails to my users using this Gmail account.

20
00:01:25,390 --> 00:01:27,550
Python will be sending those emails.

21
00:01:27,550 --> 00:01:36,250
So we need to give Python the passwords of that gmail account in app dot pi.

22
00:01:37,180 --> 00:01:47,650
So you want to access app dot config and then access mail passwords with capital letters that is equal

23
00:01:47,650 --> 00:01:48,250
to.

24
00:01:49,410 --> 00:01:51,090
The password I copied.

25
00:01:51,330 --> 00:01:57,110
And of course you also want to give the male username.

26
00:01:57,120 --> 00:02:01,590
This will be your gmail account.

27
00:02:01,590 --> 00:02:08,130
So app eight flask at gmail.com in my case.

28
00:02:08,580 --> 00:02:10,350
So male username.

29
00:02:10,350 --> 00:02:11,790
Male password.

30
00:02:15,030 --> 00:02:25,590
We also need to declare the mail server, which in my case, since I'm using Gmail, this is going to

31
00:02:25,590 --> 00:02:34,770
be smtp.gmail.com and also the port app.config.

32
00:02:36,910 --> 00:02:43,050
Male port, which for Gmail it is four, six, five.

33
00:02:43,060 --> 00:02:44,530
So a number.

34
00:02:45,370 --> 00:02:46,810
Also you want to add.

35
00:02:47,840 --> 00:02:52,220
A configuration regarding the SSL mail.

36
00:02:52,220 --> 00:02:56,300
Use SSL equal to true.

37
00:02:56,630 --> 00:03:08,930
And once you have done that, you need to import from flask mail, import mail, comma message these

38
00:03:08,930 --> 00:03:09,820
two classes.

39
00:03:09,830 --> 00:03:12,860
Flask mail is something we need to install in the terminal.

40
00:03:12,860 --> 00:03:14,360
So pip install.

41
00:03:15,490 --> 00:03:20,980
Flask minus mail rate successfully installed.

42
00:03:21,370 --> 00:03:22,780
So.

43
00:03:24,570 --> 00:03:26,610
A then down here.

44
00:03:26,610 --> 00:03:34,350
So we have the DB here and then we want to create a male instance using the male class we imported here

45
00:03:34,350 --> 00:03:37,290
and we need to connect it to the app.

46
00:03:37,290 --> 00:03:43,080
And that's how the male class will get these data right.

47
00:03:43,440 --> 00:03:49,710
So the app contains these data through the config property, which is a dictionary.

48
00:03:49,710 --> 00:03:56,670
And so the male will use those data to log in to the Gmail account and send that email.

49
00:03:57,510 --> 00:03:59,610
But we need to add something else.

50
00:03:59,610 --> 00:04:01,470
So that's the instance.

51
00:04:02,940 --> 00:04:05,340
Now we need to go to the index function.

52
00:04:06,040 --> 00:04:14,110
So in between the commit method and the flash function, we want to send out the email and then we want

53
00:04:14,110 --> 00:04:15,460
to flash the message.

54
00:04:15,910 --> 00:04:22,690
And so to send the email, we need to create a message instance.

55
00:04:22,780 --> 00:04:26,560
Message is the class we imported here, right?

56
00:04:26,860 --> 00:04:34,700
So message gets as the first argument, the subject of the email.

57
00:04:34,720 --> 00:04:36,580
New form submission, for example.

58
00:04:37,930 --> 00:04:38,920
A comma.

59
00:04:39,130 --> 00:04:41,450
Another argument will be.

60
00:04:41,470 --> 00:04:43,690
So that was the subject object.

61
00:04:44,050 --> 00:04:51,070
The second argument will be the sender, which is going to be equal to app dot config.

62
00:04:53,360 --> 00:04:55,670
Male username.

63
00:04:56,990 --> 00:04:58,880
Then we have the recipient.

64
00:05:01,730 --> 00:05:09,260
Which comes as a list because theoretically you might have to send an email to more than one email address.

65
00:05:09,260 --> 00:05:13,730
And in this case, this would be email.

66
00:05:13,760 --> 00:05:14,450
Right.

67
00:05:14,450 --> 00:05:17,000
So a list with one item.

68
00:05:17,090 --> 00:05:19,760
Email is this one in here.

69
00:05:19,760 --> 00:05:22,520
So we get the email from the user form.

70
00:05:22,520 --> 00:05:24,710
This is the user's email address.

71
00:05:24,710 --> 00:05:26,480
So the receiver.

72
00:05:27,840 --> 00:05:31,380
And lastly, the body of the message or the email.

73
00:05:31,380 --> 00:05:41,610
And this is going to be perhaps a variable which will define here message body equal to an F string

74
00:05:41,610 --> 00:05:42,420
perhaps.

75
00:05:43,320 --> 00:05:52,890
Thank you for your submission comma, and we can play around with placeholders here.

76
00:05:53,190 --> 00:05:58,410
So thank you for your submission or whatever name we get here from the form.

77
00:05:58,980 --> 00:06:01,020
Perhaps a period.

78
00:06:01,440 --> 00:06:05,010
Enter and continue the message here.

79
00:06:05,010 --> 00:06:11,010
So you have another F here, but it will be the same string stored in this message body.

80
00:06:11,910 --> 00:06:15,300
Here are your data, right?

81
00:06:15,390 --> 00:06:22,170
And then you want to say something like first name again, a break line.

82
00:06:23,990 --> 00:06:25,340
Last name.

83
00:06:26,360 --> 00:06:31,340
Break line again and then it will be the date.

84
00:06:31,760 --> 00:06:33,230
So date the string.

85
00:06:33,230 --> 00:06:35,150
We want to put the string here.

86
00:06:35,960 --> 00:06:38,490
And yes, I'll leave it with this.

87
00:06:38,510 --> 00:06:41,810
You can add more of these occupation, perhaps.

88
00:06:42,110 --> 00:06:43,790
But this is enough for now.

89
00:06:44,630 --> 00:06:48,890
Out adds another break line and in the next line I'll say thank you.

90
00:06:49,160 --> 00:06:50,120
That's it.

91
00:06:50,820 --> 00:06:57,390
So we have the message in here and then we apply mail dot send message.

92
00:06:57,570 --> 00:07:00,660
So we send this message instance, right?

93
00:07:01,260 --> 00:07:06,150
Using the mail instance, which was defined up here, Right?

94
00:07:06,150 --> 00:07:08,820
So, yeah, let's try this out.

95
00:07:11,370 --> 00:07:12,840
Let's reload first.

96
00:07:12,840 --> 00:07:14,970
Oh, it's not running, so let's run it.

97
00:07:16,110 --> 00:07:16,830
Reload.

98
00:07:19,700 --> 00:07:23,130
So I'm going to get an email to this email address.

99
00:07:23,150 --> 00:07:30,500
So this is the receiver app, a Django and my sender email address is App eight Flask.

100
00:07:35,400 --> 00:07:37,290
Employed submit.

101
00:07:39,610 --> 00:07:39,920
Right.

102
00:07:39,940 --> 00:07:41,290
So we got the notification.

103
00:07:41,290 --> 00:07:43,900
Let's check if we got a message.

104
00:07:45,180 --> 00:07:50,760
So that's App eight, Django and this is what we've got.

105
00:07:50,790 --> 00:07:54,360
Thank you for your for your submission or deteriorate your data.

106
00:07:54,780 --> 00:07:57,720
We need one more backslash n here.

107
00:07:58,230 --> 00:08:05,150
We can do that audit search and that's my date of when I want to start the job.

108
00:08:05,160 --> 00:08:06,000
Thank you.

109
00:08:06,690 --> 00:08:10,290
So between data and audit, we need.

110
00:08:12,410 --> 00:08:17,130
One more backslash n And that should fix it.

111
00:08:17,150 --> 00:08:20,330
So that's how you send out an email.

112
00:08:21,960 --> 00:08:25,040
And we used flask mail for that.

113
00:08:25,050 --> 00:08:28,530
So that makes email sending easier.

114
00:08:29,930 --> 00:08:36,919
I hope you enjoy this app and let's move on with the next app, which is going to be the same app with

115
00:08:36,919 --> 00:08:43,100
Django, but with one very important addition, an admin interface.

116
00:08:43,100 --> 00:08:48,560
Because currently what we've got here is we've got the user interface, right?

117
00:08:48,560 --> 00:08:57,530
So we get data from users and we store them in this database file which can be accessed using programs

118
00:08:57,530 --> 00:09:00,980
such as DB browser for SQLite.

119
00:09:00,980 --> 00:09:07,670
So we can see the data that has been submitted by users, but that is not ideal.

120
00:09:07,760 --> 00:09:16,130
We also want an interface, a friendly interface, a web interface for the admins, also right for the

121
00:09:16,130 --> 00:09:20,810
recruiter perhaps, or the employer who wants to see this data.

122
00:09:20,810 --> 00:09:28,280
And they don't want to go through a program such as DB browser and that can be implemented using Django.

123
00:09:28,280 --> 00:09:38,340
It can also be done with Flask, but Django is more appropriate for complete apps with an admin interface.

124
00:09:38,460 --> 00:09:41,070
So let's move on to Django.

125
00:09:41,070 --> 00:09:47,580
So you have a 360 degree skill set when it comes to web development with Python.

126
00:09:47,580 --> 00:09:50,340
So Flask and Django are really necessary to know.

127
00:09:50,340 --> 00:09:51,600
So thanks a lot for this.

128
00:09:51,600 --> 00:09:52,740
I'll see you in the next days.

129
00:09:52,770 --> 00:09:53,100
See you.

