Hey, welcome back.
We have come a long way with this app.
We were able to build the interface, get the data from the user, store them in the database, show
a notification to the user.
What's left to do now is to send a confirmation email to the user email address.
So anything that the user enters here as an email address, we should send them an email using our own
email address by our own.
I mean something you want to use for this application.
So perhaps not your personal email, but I do recommend to create a gmail account which you can use
for this.
So here I have one and the first thing you want to do in Gmail is you want to go to manage your Google
account and you want to go to security and you need to turn on two step verification.
If you haven't done that already, once you do that, you should go to app passwords again in security
and you want to create a new app password here.
So select other pick a name for this Flask application form, click on Generate and you want to copy
that.
That is the password of this Google account.
App flask.
So I'll be sending emails to my users using this Gmail account.
Python will be sending those emails.
So we need to give Python the passwords of that gmail account in app dot pi.
So you want to access app dot config and then access mail passwords with capital letters that is equal
to.
The password I copied.
And of course you also want to give the male username.
This will be your gmail account.
So app eight flask at gmail.com in my case.
So male username.
Male password.
We also need to declare the mail server, which in my case, since I'm using Gmail, this is going to
be smtp.gmail.com and also the port app.config.
Male port, which for Gmail it is four, six, five.
So a number.
Also you want to add.
A configuration regarding the SSL mail.
Use SSL equal to true.
And once you have done that, you need to import from flask mail, import mail, comma message these
two classes.
Flask mail is something we need to install in the terminal.
So pip install.
Flask minus mail rate successfully installed.
So.
A then down here.
So we have the DB here and then we want to create a male instance using the male class we imported here
and we need to connect it to the app.
And that's how the male class will get these data right.
So the app contains these data through the config property, which is a dictionary.
And so the male will use those data to log in to the Gmail account and send that email.
But we need to add something else.
So that's the instance.
Now we need to go to the index function.
So in between the commit method and the flash function, we want to send out the email and then we want
to flash the message.
And so to send the email, we need to create a message instance.
Message is the class we imported here, right?
So message gets as the first argument, the subject of the email.
New form submission, for example.
A comma.
Another argument will be.
So that was the subject object.
The second argument will be the sender, which is going to be equal to app dot config.
Male username.
Then we have the recipient.
Which comes as a list because theoretically you might have to send an email to more than one email address.
And in this case, this would be email.
Right.
So a list with one item.
Email is this one in here.
So we get the email from the user form.
This is the user's email address.
So the receiver.
And lastly, the body of the message or the email.
And this is going to be perhaps a variable which will define here message body equal to an F string
perhaps.
Thank you for your submission comma, and we can play around with placeholders here.
So thank you for your submission or whatever name we get here from the form.
Perhaps a period.
Enter and continue the message here.
So you have another F here, but it will be the same string stored in this message body.
Here are your data, right?
And then you want to say something like first name again, a break line.
Last name.
Break line again and then it will be the date.
So date the string.
We want to put the string here.
And yes, I'll leave it with this.
You can add more of these occupation, perhaps.
But this is enough for now.
Out adds another break line and in the next line I'll say thank you.
That's it.
So we have the message in here and then we apply mail dot send message.
So we send this message instance, right?
Using the mail instance, which was defined up here, Right?
So, yeah, let's try this out.
Let's reload first.
Oh, it's not running, so let's run it.
Reload.
So I'm going to get an email to this email address.
So this is the receiver app, a Django and my sender email address is App eight Flask.
Employed submit.
Right.
So we got the notification.
Let's check if we got a message.
So that's App eight, Django and this is what we've got.
Thank you for your for your submission or deteriorate your data.
We need one more backslash n here.
We can do that audit search and that's my date of when I want to start the job.
Thank you.
So between data and audit, we need.
One more backslash n And that should fix it.
So that's how you send out an email.
And we used flask mail for that.
So that makes email sending easier.
I hope you enjoy this app and let's move on with the next app, which is going to be the same app with
Django, but with one very important addition, an admin interface.
Because currently what we've got here is we've got the user interface, right?
So we get data from users and we store them in this database file which can be accessed using programs
such as DB browser for SQLite.
So we can see the data that has been submitted by users, but that is not ideal.
We also want an interface, a friendly interface, a web interface for the admins, also right for the
recruiter perhaps, or the employer who wants to see this data.
And they don't want to go through a program such as DB browser and that can be implemented using Django.
It can also be done with Flask, but Django is more appropriate for complete apps with an admin interface.
So let's move on to Django.
So you have a 360 degree skill set when it comes to web development with Python.
So Flask and Django are really necessary to know.
So thanks a lot for this.
I'll see you in the next days.
See you.