1 00:00:01,100 --> 00:00:08,030 Hello, friends, in this video, we shall see how to use the flask male extension. 2 00:00:15,570 --> 00:00:24,060 EMAC General-Purpose Web application, it is often required that the application must have an email 3 00:00:24,270 --> 00:00:25,050 sending. 4 00:00:25,990 --> 00:00:26,570 Facility. 5 00:00:27,010 --> 00:00:33,940 So this email support feature can be activated in your application by using the flask mail extension. 6 00:00:36,090 --> 00:00:42,810 Flask mail extension can be installed in the flask and worn by two different. 7 00:00:43,200 --> 00:00:47,590 This one is a straightforward utility can be used. 8 00:00:47,610 --> 00:00:49,950 You can pip install flask M.. 9 00:00:51,600 --> 00:00:58,460 So because the last male extension is holstered on the pipeline, that is the Python package index, 10 00:00:59,370 --> 00:01:04,710 it can be easily installed by using the utility, but in case in some. 11 00:01:05,820 --> 00:01:11,700 Operating system platforms are in some environments, the utility is. 12 00:01:12,700 --> 00:01:20,920 Not able to install it, then the better the other alternative is to download the latest version of 13 00:01:20,920 --> 00:01:29,890 this e-mail from this git repository and then install by saying set up what you are installed. 14 00:01:30,790 --> 00:01:36,820 So this is the installation from code and this is the installation by the help of the utility, any 15 00:01:36,820 --> 00:01:38,170 of which can be used. 16 00:01:42,240 --> 00:01:50,940 After the flask extension has been installed or has been incorporated into a flask environment, then 17 00:01:51,570 --> 00:01:58,320 Quada for its use to be done with the help of the inside of the flask application, the flask application 18 00:01:58,320 --> 00:01:59,820 must be properly configured. 19 00:02:01,140 --> 00:02:07,800 And these are the different configuration settings that you may have to provide in your application. 20 00:02:08,670 --> 00:02:16,890 For example, you have to provide or specify the mail server setting mail server is about the name or 21 00:02:16,890 --> 00:02:18,750 IP address of your e-mail server. 22 00:02:19,710 --> 00:02:27,300 That you must specify in this configuration, mainboard board, the server and the port number have 23 00:02:27,300 --> 00:02:28,440 to be specified. 24 00:02:29,380 --> 00:02:38,300 On Witchboard, the email server is going to keep on listening the requests use less and use SSL. 25 00:02:38,330 --> 00:02:45,880 These are the two settings configurations which will either enable or disable the transport security 26 00:02:45,880 --> 00:02:50,650 layer or SSL encryption support can be enabled or disable. 27 00:02:50,650 --> 00:02:54,630 Both of them are boolean function boolean settings. 28 00:02:55,030 --> 00:02:57,820 So is the debug is also a boolean setting. 29 00:02:57,820 --> 00:03:00,700 It can be enabled or disable. 30 00:03:00,700 --> 00:03:03,940 It will either enable the debug support or disable. 31 00:03:04,600 --> 00:03:04,980 Right. 32 00:03:05,500 --> 00:03:08,650 Then these two settings are the most important ones. 33 00:03:09,820 --> 00:03:14,840 You have to first set up the username and password of the sender. 34 00:03:14,860 --> 00:03:18,340 So that means basically you're to log into your email server. 35 00:03:19,210 --> 00:03:22,410 These two are username and password settings. 36 00:03:23,320 --> 00:03:25,780 You can also specify the default sender. 37 00:03:28,310 --> 00:03:34,820 You can set the maximum image that can be sent at one through one round of application. 38 00:03:36,690 --> 00:03:45,930 Melissa precent is a barometer, is an attribute if the standing is suppressed, if the app testing 39 00:03:45,930 --> 00:03:46,830 is to prove. 40 00:03:48,220 --> 00:03:56,740 And lastly, there is a male askey attachment setting, if it is true, then attach the filenames are 41 00:03:56,740 --> 00:03:58,180 converted into an ASCII. 42 00:03:59,290 --> 00:04:07,930 These are some of the important attributes or settings that you have to provide or properly set in the 43 00:04:08,260 --> 00:04:10,360 application configuration settings. 44 00:04:14,800 --> 00:04:17,960 The plastic extension has two important classes. 45 00:04:18,670 --> 00:04:21,520 One is the middle class and the other is a message class. 46 00:04:22,600 --> 00:04:26,380 The middle class manages the email messaging requirements. 47 00:04:28,210 --> 00:04:37,780 The glass constructor takes a very simple and straightforward form flask, male or male, in the bracket, 48 00:04:37,810 --> 00:04:47,080 the name of the application object, and these three very important functions associated in the class 49 00:04:47,260 --> 00:04:48,490 are frequently used. 50 00:04:48,850 --> 00:04:53,950 Sand is a function of obviously a very important function because it sends the content of the message 51 00:04:53,950 --> 00:04:55,060 glass object. 52 00:04:56,590 --> 00:05:04,150 Connect, it opens the connection with the video, we must provide the host name and airport name in 53 00:05:04,150 --> 00:05:10,900 the configuration settings using those settings the server will be connected to with the help of the 54 00:05:10,900 --> 00:05:11,610 connect function. 55 00:05:11,980 --> 00:05:12,880 And then there is it. 56 00:05:12,880 --> 00:05:15,640 Send message functions, sends the message. 57 00:05:16,360 --> 00:05:21,750 So these three are the important matters that are defined in the middle class. 58 00:05:22,420 --> 00:05:23,650 This is about the middle class. 59 00:05:23,890 --> 00:05:28,800 The other class that is present in the extension is called the message class. 60 00:05:29,770 --> 00:05:37,630 This message class controls are embedded encapsulates is the proper word and e-mail message. 61 00:05:39,310 --> 00:05:42,790 The message glass constrictor has several parents. 62 00:05:43,790 --> 00:05:45,710 This is a list of the different parameters. 63 00:05:47,050 --> 00:05:56,910 Which is in the name of the class subject recipients, one of the many recipients, maybe their body, 64 00:05:56,920 --> 00:06:06,790 the actual text of message as HTML sender is, of course, provided the information of the sender is 65 00:06:06,970 --> 00:06:08,980 already provided in the application settings. 66 00:06:10,270 --> 00:06:11,650 Cissie NBCC. 67 00:06:12,760 --> 00:06:21,100 They reply to their characters, characters, set Heather's meal options, recipient options, etc., 68 00:06:21,100 --> 00:06:24,820 etc., these are all the different parameters that you can provide. 69 00:06:25,390 --> 00:06:27,970 Some of them, or many of them, rather, are optional. 70 00:06:27,970 --> 00:06:32,380 For example, is optional mail options. 71 00:06:32,560 --> 00:06:36,550 Recipient options can be optionally you are ignored like that. 72 00:06:38,160 --> 00:06:43,490 What are the different and important message class matters, one is at that. 73 00:06:44,820 --> 00:06:52,380 If you want to send a certain resource as an attachment to the mail, as an attachment to the message, 74 00:06:52,680 --> 00:06:56,710 this method takes following parameters which file name to be attached. 75 00:06:57,060 --> 00:07:05,580 What is the content type, whether it is a text file or image file or what type of file this data and 76 00:07:05,580 --> 00:07:09,190 disposition, the content, disposition, etc., if there is any. 77 00:07:09,650 --> 00:07:14,850 So these are all the different parameters to the attach function and our recipient is another matter 78 00:07:15,240 --> 00:07:17,880 and another recipient of the message. 79 00:07:18,360 --> 00:07:18,840 So. 80 00:07:20,130 --> 00:07:26,340 In order to board, the classes are very important for performing the male sending activity, so therefore 81 00:07:26,340 --> 00:07:28,180 both these classes must be important. 82 00:07:28,770 --> 00:07:36,420 The last male import male and this is a very mandatory statement that you must write. 83 00:07:40,210 --> 00:07:40,660 So. 84 00:07:41,930 --> 00:07:53,180 Using this in our discussion as a basis, we shall now see how to send the email using the Gmail, Gmail 85 00:07:53,180 --> 00:08:00,340 is a very popular e-mail that we value you, all of you must be doing using that Gmail, Gmail, SMTP 86 00:08:00,350 --> 00:08:00,760 server. 87 00:08:00,770 --> 00:08:08,990 We will use as a as our server and then try to send email to our by chance application. 88 00:08:09,710 --> 00:08:11,170 So this is the application setting. 89 00:08:12,200 --> 00:08:15,980 Most importantly at dot config mail server setting. 90 00:08:15,980 --> 00:08:21,680 I'm using the name of the assembly server of the Gmail service. 91 00:08:21,980 --> 00:08:23,990 So SBP Gmail dot com. 92 00:08:24,890 --> 00:08:28,370 The recommended number by Gmail is four six five. 93 00:08:31,330 --> 00:08:32,590 Username and password. 94 00:08:33,940 --> 00:08:41,710 You must be a user of G.M., of course, in order to use email, SMTP password cannot be rebuilt, so 95 00:08:41,710 --> 00:08:50,380 therefore I am putting starts beardless and assesses these two parameters to force us to do this. 96 00:08:50,380 --> 00:08:59,760 Is the configuration very important, that basic activity that you must perform inside the application 97 00:08:59,770 --> 00:09:02,090 would first create the application. 98 00:09:02,140 --> 00:09:06,640 The object of the middle class, then create the object of the message class. 99 00:09:08,220 --> 00:09:15,120 By giving the parameters that are mandatory, like, for example, the message center and disappears. 100 00:09:16,050 --> 00:09:20,560 Rest of the parameters that we saw in the earlier slide are all optional. 101 00:09:21,910 --> 00:09:25,630 OK, and then same message, not body is equal to the lower floors. 102 00:09:25,660 --> 00:09:30,510 The message sent from some such thing will be said as the body of the message. 103 00:09:30,820 --> 00:09:32,790 And then this it mailed or said. 104 00:09:34,150 --> 00:09:42,640 OK, so this is the brief gist of all the activities that you have to incorporate in your 105 00:09:45,310 --> 00:09:49,570 training program using a SMTP server of the JEIMY. 106 00:09:50,410 --> 00:09:53,180 Now, incidentally, one more precaution has to be taken. 107 00:09:54,100 --> 00:09:54,760 What is that? 108 00:09:55,330 --> 00:10:01,840 Since you are using the Gmail service, are Gmail servers, SFP service? 109 00:10:02,260 --> 00:10:06,490 Gmail does not allow normally the. 110 00:10:07,860 --> 00:10:12,370 Males to be sent by a third party in a product. 111 00:10:13,140 --> 00:10:21,390 So therefore, when you are trying to send or use the same server to our third to our total program 112 00:10:21,390 --> 00:10:24,960 as a third party program for G.M., so therefore it will block it. 113 00:10:26,700 --> 00:10:34,020 So therefore, in order to let G.M. allow senators to send a message through our application, you will 114 00:10:34,020 --> 00:10:40,760 have to perform a slight, you know, setting to our Gmail account settings. 115 00:10:40,950 --> 00:10:41,720 And what is that? 116 00:10:42,150 --> 00:10:49,050 Go to this particular you are in Google dot com settings, security, less secure apps. 117 00:10:50,290 --> 00:10:53,170 So the less secure apps are normally set to. 118 00:10:54,450 --> 00:11:03,330 If it doesn't allow the less secure apps to be used to enable that support, then only this program 119 00:11:03,330 --> 00:11:08,340 will be able to send the message to the recipient that we have mentioned. 120 00:11:08,760 --> 00:11:20,400 So this is a very useful feature of last application by which you can either email support your application 121 00:11:20,820 --> 00:11:28,680 and especially this Gmail SMTP Gmail service that is that I'm demonstrating to you. 122 00:11:28,920 --> 00:11:37,200 I will now actually do this exercise in front of you, write a program, perform the settings, change 123 00:11:37,200 --> 00:11:46,740 the secure application settings, and then send the mail through the application and check in the Gmail 124 00:11:46,740 --> 00:11:50,160 account, go in the G.M. account, see whether the mail has been delivered or not. 125 00:11:50,430 --> 00:11:53,490 All this I will do as an exercise in front of you. 126 00:11:54,570 --> 00:12:01,770 So first of all, we have to verify whether the flask mail extension has been properly installed in 127 00:12:01,770 --> 00:12:04,630 our working class environment or not. 128 00:12:05,220 --> 00:12:06,330 So I have already. 129 00:12:07,300 --> 00:12:09,010 Started our activity, activated the. 130 00:12:10,020 --> 00:12:11,220 Virtual environment. 131 00:12:12,200 --> 00:12:12,740 And. 132 00:12:13,860 --> 00:12:22,040 Now, inside this, I will have to see whether this flask, male extension has been installed or not, 133 00:12:22,440 --> 00:12:28,080 how to verify that, just try to reinstall installed again by using the pipe. 134 00:12:28,530 --> 00:12:30,660 If if it is not there, it will be installed. 135 00:12:30,660 --> 00:12:32,930 Otherwise, it will say it will be all it is already present. 136 00:12:32,980 --> 00:12:33,690 So let us see. 137 00:12:34,870 --> 00:12:35,770 Uh. 138 00:12:36,640 --> 00:12:39,490 It is available in the. 139 00:12:39,850 --> 00:12:42,850 Utility is available in scripts folder. 140 00:12:54,030 --> 00:12:56,430 Flask is the name of the extension. 141 00:13:00,080 --> 00:13:02,970 So the requirement is already fulfilled or satisfied. 142 00:13:02,990 --> 00:13:05,240 That means the last mile extension is. 143 00:13:06,240 --> 00:13:06,840 Instore. 144 00:13:07,740 --> 00:13:13,380 Another way of verification, verification or verifying it is that start the Python interpreter. 145 00:13:16,800 --> 00:13:17,820 And Chambord. 146 00:13:22,520 --> 00:13:25,420 If it is able to import, then that means it is installed. 147 00:13:31,440 --> 00:13:37,400 So that means blackmail is properly installed in this in this virtual environment. 148 00:13:38,900 --> 00:13:41,390 And now this is the classic application called. 149 00:13:42,970 --> 00:13:49,360 In the beginning, you have to import the glass from the flask module, also important mail and message 150 00:13:49,360 --> 00:13:50,320 glasses from the. 151 00:13:51,660 --> 00:13:54,630 Extension that we just now install flask male. 152 00:13:56,350 --> 00:13:57,910 Set up the application object. 153 00:13:59,040 --> 00:14:00,540 Applicable to flask. 154 00:14:01,690 --> 00:14:06,550 Double underscored name, this ape object is the argument. 155 00:14:08,400 --> 00:14:13,560 To the middle class constructor's, this is a male object object of the middle class. 156 00:14:15,150 --> 00:14:22,560 Then this is necessary to do certain configuration settings to your application class by. 157 00:14:23,660 --> 00:14:26,160 Specifying the mail server. 158 00:14:26,600 --> 00:14:30,980 Here we are going to use the SMTP server of the G Mail. 159 00:14:32,120 --> 00:14:40,130 Service, so the name of the S&P, Sahuarita Centipede or Gmail dot com, the recommended port number 160 00:14:40,130 --> 00:14:41,070 is 465. 161 00:14:42,260 --> 00:14:48,830 These are the login credentials, the username and password, and these are the security settings. 162 00:14:49,280 --> 00:14:51,650 I am setting Gmail use Steeles. 163 00:14:52,560 --> 00:14:58,050 Parameter of the configuration dot com equal to false, but SSL is equal to two. 164 00:14:58,900 --> 00:14:59,740 So these are all. 165 00:15:00,790 --> 00:15:03,790 The configuration settings that you must enable. 166 00:15:05,620 --> 00:15:11,320 And now to this route, you are in the index function that is mapped. 167 00:15:12,840 --> 00:15:19,440 Inside, which what is happening, I am setting up a message glass object, and it takes three. 168 00:15:21,390 --> 00:15:28,980 Mandatory arguments, the subject, the sender and the recipient, the sender and discipline it is. 169 00:15:29,930 --> 00:15:35,330 And then the body attribute of this message object, this is the. 170 00:15:36,290 --> 00:15:37,670 Text that you want to. 171 00:15:38,960 --> 00:15:46,250 Send us an e-mail and then you just send a matter of the middle class, the matter will be sent as the 172 00:15:46,250 --> 00:15:47,210 message will be sent. 173 00:15:48,640 --> 00:15:51,190 OK, so this is the application called. 174 00:15:52,240 --> 00:15:59,710 But before running the Python application code, the flask application called you to do one more sting 175 00:15:59,950 --> 00:16:05,050 operation, go to this, you are ill after logging into your. 176 00:16:06,550 --> 00:16:14,440 Gmail account open, Google dot com settings, security and less secure apps and ensure that access 177 00:16:14,440 --> 00:16:19,420 for less secure apps is turned on by the authorities of. 178 00:16:20,930 --> 00:16:30,520 Because the G mail service or the e-mail server does not allow mail to be sent by any third party applications, 179 00:16:31,130 --> 00:16:35,630 now that our application, our application will not be. 180 00:16:36,490 --> 00:16:42,670 You're not allowed to send the mail on behalf of the Gmail service, so therefore in order to let the 181 00:16:42,670 --> 00:16:43,960 Gmail allow that. 182 00:16:46,130 --> 00:16:56,330 Turn this thing on access for less secure apps, turn it on, so that is very essential for the successful 183 00:16:56,330 --> 00:16:57,360 execution of your. 184 00:16:58,670 --> 00:17:00,200 Now, coming back to the. 185 00:17:01,710 --> 00:17:07,110 Virtual Environment Command prompt now executed that this mailed by. 186 00:17:08,090 --> 00:17:15,080 But on Milhaud, before we start the server, so the server is starting right now with it, go in the 187 00:17:15,080 --> 00:17:16,310 browser and visit this. 188 00:17:16,310 --> 00:17:18,520 You are in localhost 5000 slash. 189 00:17:19,490 --> 00:17:27,580 So I open the browser and, you know, given the you are a localhost 5000 slash. 190 00:17:28,890 --> 00:17:36,960 As soon as I press enter the message on my brother's messages sent through in order to verify that the 191 00:17:36,960 --> 00:17:39,630 messages sent and go in my inbox. 192 00:17:41,210 --> 00:17:44,200 And there you see the message, hello. 193 00:17:44,480 --> 00:17:51,500 It was the subject of the message, hello, flask, this message is sent from the last was my body of 194 00:17:51,500 --> 00:17:51,960 the message. 195 00:17:52,250 --> 00:17:57,680 So that is all you can use this as SMTP server of G.M.. 196 00:17:58,820 --> 00:18:03,660 To send an e-mail message through our flask application. 197 00:18:03,710 --> 00:18:06,380 So this was a demonstration of the intent exercise.