WEBVTT

00:00.110 --> 00:06.290
And now, finally, we can actually use the YAML module to send our first email from the Raspberry Pi.

00:06.320 --> 00:12.590
So there was a bit of setup, but after this setup, well, you will be able to send emails very quickly

00:12.590 --> 00:13.700
and very easily.

00:13.700 --> 00:16.370
I'm going to keep this code here with the password okay.

00:16.400 --> 00:23.900
And what I will do at the beginning of the program is to first import the import Yaghmaian.

00:25.370 --> 00:30.080
It's going to do that, and I make sure I go back to the previous indentation here.

00:30.110 --> 00:37.550
And so to send an email you first need to create an email client okay I'm going to create that inside

00:37.550 --> 00:38.030
a variable.

00:38.030 --> 00:43.100
I'm just going to call it YAG is equal to your gmail dot.

00:43.100 --> 00:46.430
And then SMTP all uppercase.

00:46.430 --> 00:48.560
And you're going to open and close the parentheses.

00:48.560 --> 00:50.180
And here you need to give two things.

00:50.180 --> 00:55.310
First the email address that you want to send from and then the password.

00:55.310 --> 00:57.290
So that's going to be the app password.

00:57.290 --> 01:00.020
Once again it's not the password of the Google account.

01:00.020 --> 01:01.130
It's the app password.

01:01.130 --> 01:10.820
So for me it's course cool that Raspberry Pi at gmail.com, so make sure you put your email address

01:10.820 --> 01:12.920
instead the one that you have created.

01:12.920 --> 01:18.200
And then I put the password variable that I have just created in the last lesson.

01:18.200 --> 01:20.150
Now I can send an email.

01:20.150 --> 01:21.350
So I'm going to do.

01:21.380 --> 01:21.650
Yeah.

01:21.740 --> 01:28.790
So that's my Gmail client dot send as simple as this.

01:28.790 --> 01:31.730
And I will need to provide a few arguments.

01:31.730 --> 01:35.570
And for those arguments I first need to provide the name of the argument like this.

01:35.570 --> 01:38.090
So two and then equal.

01:38.240 --> 01:40.310
And I put some quotes.

01:40.310 --> 01:46.850
So this is the email address that I want to send to here I'm going to put my personal email address.

01:50.000 --> 01:50.180
Okay.

01:50.180 --> 01:53.810
So I don't show you of course because it's my personal address.

01:53.810 --> 01:59.300
And that's where I want to receive the emails from the Raspberry Pi.

01:59.330 --> 02:03.170
I'm going to put a colon and then I go back to a new line with enter.

02:03.200 --> 02:07.460
You can see that when I go back to a new line, it's automatically indented here.

02:07.460 --> 02:10.640
You don't really need to do that, but it's just better for readability.

02:10.670 --> 02:11.030
Okay.

02:11.060 --> 02:15.440
And instead of adding all the arguments here to the same line, which is going to be very long, you

02:15.440 --> 02:17.660
can add one per line, it's easier to read.

02:17.660 --> 02:18.740
So we have two.

02:18.770 --> 02:22.880
Then we will have subject equal okay.

02:22.880 --> 02:31.490
So the subject of the email let's say first email I put a comma, go back to a new line and then contents

02:31.490 --> 02:33.560
with an S is equal to.

02:33.590 --> 02:35.840
And that's going to be the content of the email.

02:36.440 --> 02:40.220
Let's say hello from Raspberry Pi.

02:40.490 --> 02:41.630
And that's it for now.

02:41.630 --> 02:44.150
So I'm going to close the parentheses okay.

02:44.180 --> 02:47.870
We have two subjects and contents.

02:47.870 --> 02:51.500
Then I go back to a new line actually that's it okay.

02:51.530 --> 02:53.120
The code is finished.

02:53.120 --> 02:54.500
You can send with that.

02:54.530 --> 02:59.540
I'm just going to add a print email sent okay.

02:59.570 --> 03:01.670
Just so we have an output in the program.

03:01.700 --> 03:04.850
Otherwise you will run it and you will see nothing.

03:04.850 --> 03:06.920
So let's run that.

03:08.610 --> 03:08.970
okay.

03:09.000 --> 03:10.020
It's taking.

03:10.050 --> 03:16.590
Well, it took me 1 or 2 seconds and then you see email sent just to show you if, for example, I put

03:16.590 --> 03:23.340
a wrong email address or a wrong password, if I try to run it, we should have an error like this.

03:23.370 --> 03:23.610
Okay.

03:23.640 --> 03:27.120
So username and password not accepted.

03:27.330 --> 03:27.630
Okay.

03:27.660 --> 03:31.890
So if you have this error make sure that you have put the correct email address.

03:31.890 --> 03:37.950
And if this is correct then make sure that you correctly read the password okay from the file and that

03:37.950 --> 03:39.090
everything is correct.

03:39.090 --> 03:41.610
So you might need to go back also to your Google account.

03:41.640 --> 03:43.290
Maybe create a new app password.

03:43.290 --> 03:45.540
Just make sure that you have the correct combination.

03:45.990 --> 03:48.960
So I am now seeing my email inbox.

03:48.960 --> 03:50.070
So that's the email.

03:50.070 --> 03:51.780
So that's my personal email right.

03:51.810 --> 03:55.710
So I used the Raspberry Pi email to send to my personal email.

03:55.710 --> 04:01.590
And I have received a new email you see from course dot Raspberry Pi at gmail.com.

04:01.590 --> 04:02.940
So I'm going to open that.

04:02.940 --> 04:06.420
And you see the subject is first email and we have the content.

04:06.450 --> 04:08.130
Hello from Raspberry Pi.

04:08.160 --> 04:10.290
So it correctly worked.
