Hello, friends, in this video, we shall see how to use the flask male extension.
EMAC General-Purpose Web application, it is often required that the application must have an email
sending.
Facility.
So this email support feature can be activated in your application by using the flask mail extension.
Flask mail extension can be installed in the flask and worn by two different.
This one is a straightforward utility can be used.
You can pip install flask M..
So because the last male extension is holstered on the pipeline, that is the Python package index,
it can be easily installed by using the utility, but in case in some.
Operating system platforms are in some environments, the utility is.
Not able to install it, then the better the other alternative is to download the latest version of
this e-mail from this git repository and then install by saying set up what you are installed.
So this is the installation from code and this is the installation by the help of the utility, any
of which can be used.
After the flask extension has been installed or has been incorporated into a flask environment, then
Quada for its use to be done with the help of the inside of the flask application, the flask application
must be properly configured.
And these are the different configuration settings that you may have to provide in your application.
For example, you have to provide or specify the mail server setting mail server is about the name or
IP address of your e-mail server.
That you must specify in this configuration, mainboard board, the server and the port number have
to be specified.
On Witchboard, the email server is going to keep on listening the requests use less and use SSL.
These are the two settings configurations which will either enable or disable the transport security
layer or SSL encryption support can be enabled or disable.
Both of them are boolean function boolean settings.
So is the debug is also a boolean setting.
It can be enabled or disable.
It will either enable the debug support or disable.
Right.
Then these two settings are the most important ones.
You have to first set up the username and password of the sender.
So that means basically you're to log into your email server.
These two are username and password settings.
You can also specify the default sender.
You can set the maximum image that can be sent at one through one round of application.
Melissa precent is a barometer, is an attribute if the standing is suppressed, if the app testing
is to prove.
And lastly, there is a male askey attachment setting, if it is true, then attach the filenames are
converted into an ASCII.
These are some of the important attributes or settings that you have to provide or properly set in the
application configuration settings.
The plastic extension has two important classes.
One is the middle class and the other is a message class.
The middle class manages the email messaging requirements.
The glass constructor takes a very simple and straightforward form flask, male or male, in the bracket,
the name of the application object, and these three very important functions associated in the class
are frequently used.
Sand is a function of obviously a very important function because it sends the content of the message
glass object.
Connect, it opens the connection with the video, we must provide the host name and airport name in
the configuration settings using those settings the server will be connected to with the help of the
connect function.
And then there is it.
Send message functions, sends the message.
So these three are the important matters that are defined in the middle class.
This is about the middle class.
The other class that is present in the extension is called the message class.
This message class controls are embedded encapsulates is the proper word and e-mail message.
The message glass constrictor has several parents.
This is a list of the different parameters.
Which is in the name of the class subject recipients, one of the many recipients, maybe their body,
the actual text of message as HTML sender is, of course, provided the information of the sender is
already provided in the application settings.
Cissie NBCC.
They reply to their characters, characters, set Heather's meal options, recipient options, etc.,
etc., these are all the different parameters that you can provide.
Some of them, or many of them, rather, are optional.
For example, is optional mail options.
Recipient options can be optionally you are ignored like that.
What are the different and important message class matters, one is at that.
If you want to send a certain resource as an attachment to the mail, as an attachment to the message,
this method takes following parameters which file name to be attached.
What is the content type, whether it is a text file or image file or what type of file this data and
disposition, the content, disposition, etc., if there is any.
So these are all the different parameters to the attach function and our recipient is another matter
and another recipient of the message.
So.
In order to board, the classes are very important for performing the male sending activity, so therefore
both these classes must be important.
The last male import male and this is a very mandatory statement that you must write.
So.
Using this in our discussion as a basis, we shall now see how to send the email using the Gmail, Gmail
is a very popular e-mail that we value you, all of you must be doing using that Gmail, Gmail, SMTP
server.
We will use as a as our server and then try to send email to our by chance application.
So this is the application setting.
Most importantly at dot config mail server setting.
I'm using the name of the assembly server of the Gmail service.
So SBP Gmail dot com.
The recommended number by Gmail is four six five.
Username and password.
You must be a user of G.M., of course, in order to use email, SMTP password cannot be rebuilt, so
therefore I am putting starts beardless and assesses these two parameters to force us to do this.
Is the configuration very important, that basic activity that you must perform inside the application
would first create the application.
The object of the middle class, then create the object of the message class.
By giving the parameters that are mandatory, like, for example, the message center and disappears.
Rest of the parameters that we saw in the earlier slide are all optional.
OK, and then same message, not body is equal to the lower floors.
The message sent from some such thing will be said as the body of the message.
And then this it mailed or said.
OK, so this is the brief gist of all the activities that you have to incorporate in your
training program using a SMTP server of the JEIMY.
Now, incidentally, one more precaution has to be taken.
What is that?
Since you are using the Gmail service, are Gmail servers, SFP service?
Gmail does not allow normally the.
Males to be sent by a third party in a product.
So therefore, when you are trying to send or use the same server to our third to our total program
as a third party program for G.M., so therefore it will block it.
So therefore, in order to let G.M. allow senators to send a message through our application, you will
have to perform a slight, you know, setting to our Gmail account settings.
And what is that?
Go to this particular you are in Google dot com settings, security, less secure apps.
So the less secure apps are normally set to.
If it doesn't allow the less secure apps to be used to enable that support, then only this program
will be able to send the message to the recipient that we have mentioned.
So this is a very useful feature of last application by which you can either email support your application
and especially this Gmail SMTP Gmail service that is that I'm demonstrating to you.
I will now actually do this exercise in front of you, write a program, perform the settings, change
the secure application settings, and then send the mail through the application and check in the Gmail
account, go in the G.M. account, see whether the mail has been delivered or not.
All this I will do as an exercise in front of you.
So first of all, we have to verify whether the flask mail extension has been properly installed in
our working class environment or not.
So I have already.
Started our activity, activated the.
Virtual environment.
And.
Now, inside this, I will have to see whether this flask, male extension has been installed or not,
how to verify that, just try to reinstall installed again by using the pipe.
If if it is not there, it will be installed.
Otherwise, it will say it will be all it is already present.
So let us see.
Uh.
It is available in the.
Utility is available in scripts folder.
Flask is the name of the extension.
So the requirement is already fulfilled or satisfied.
That means the last mile extension is.
Instore.
Another way of verification, verification or verifying it is that start the Python interpreter.
And Chambord.
If it is able to import, then that means it is installed.
So that means blackmail is properly installed in this in this virtual environment.
And now this is the classic application called.
In the beginning, you have to import the glass from the flask module, also important mail and message
glasses from the.
Extension that we just now install flask male.
Set up the application object.
Applicable to flask.
Double underscored name, this ape object is the argument.
To the middle class constructor's, this is a male object object of the middle class.
Then this is necessary to do certain configuration settings to your application class by.
Specifying the mail server.
Here we are going to use the SMTP server of the G Mail.
Service, so the name of the S&P, Sahuarita Centipede or Gmail dot com, the recommended port number
is 465.
These are the login credentials, the username and password, and these are the security settings.
I am setting Gmail use Steeles.
Parameter of the configuration dot com equal to false, but SSL is equal to two.
So these are all.
The configuration settings that you must enable.
And now to this route, you are in the index function that is mapped.
Inside, which what is happening, I am setting up a message glass object, and it takes three.
Mandatory arguments, the subject, the sender and the recipient, the sender and discipline it is.
And then the body attribute of this message object, this is the.
Text that you want to.
Send us an e-mail and then you just send a matter of the middle class, the matter will be sent as the
message will be sent.
OK, so this is the application called.
But before running the Python application code, the flask application called you to do one more sting
operation, go to this, you are ill after logging into your.
Gmail account open, Google dot com settings, security and less secure apps and ensure that access
for less secure apps is turned on by the authorities of.
Because the G mail service or the e-mail server does not allow mail to be sent by any third party applications,
now that our application, our application will not be.
You're not allowed to send the mail on behalf of the Gmail service, so therefore in order to let the
Gmail allow that.
Turn this thing on access for less secure apps, turn it on, so that is very essential for the successful
execution of your.
Now, coming back to the.
Virtual Environment Command prompt now executed that this mailed by.
But on Milhaud, before we start the server, so the server is starting right now with it, go in the
browser and visit this.
You are in localhost 5000 slash.
So I open the browser and, you know, given the you are a localhost 5000 slash.
As soon as I press enter the message on my brother's messages sent through in order to verify that the
messages sent and go in my inbox.
And there you see the message, hello.
It was the subject of the message, hello, flask, this message is sent from the last was my body of
the message.
So that is all you can use this as SMTP server of G.M..
To send an e-mail message through our flask application.
So this was a demonstration of the intent exercise.