WEBVTT

00:00.080 --> 00:05.450
To finish this quite quick section, we are going to see how to add an attachment to an email.

00:05.480 --> 00:09.410
Okay, that's going to be very useful also for the final project of the course.

00:09.410 --> 00:11.720
So we can send any file we want.

00:11.750 --> 00:17.120
Let's make a quick test with just a text file that I'm going to create here on the Raspberry Pi.

00:17.120 --> 00:22.610
So I open a new terminal and well let's create it in the home directory okay.

00:22.640 --> 00:27.890
We can create a file with touch or directly with Nano because I'm going to write to it.

00:27.920 --> 00:31.730
So nano file to join.

00:31.730 --> 00:39.650
And let's add an extension okay dot txt because then if I open the email let's say on windows and I

00:39.680 --> 00:44.300
download this file here and I want to open it, maybe it's going to be easier with a txt extension.

00:44.300 --> 00:48.440
So nano file to join dot txt and let's write.

00:48.440 --> 00:55.640
This text file has been created under Raspberry Pi okay.

00:55.670 --> 00:59.150
You can write whatever you want Ctrl s Ctrl x.

00:59.180 --> 00:59.810
Great.

00:59.810 --> 01:04.460
Now we have our file here and how to send that file through email.

01:04.460 --> 01:05.780
Well you just go back to the code.

01:05.780 --> 01:09.260
Here we have two subject contents.

01:09.350 --> 01:11.120
You're going to add a comma here.

01:11.150 --> 01:12.410
Go back to a new line.

01:12.410 --> 01:15.980
And we are going to put attachments okay.

01:16.010 --> 01:16.760
With an S.

01:16.790 --> 01:22.260
Then you are going to put an equal again and the path to the file.

01:22.260 --> 01:23.010
So here.

01:23.040 --> 01:23.850
Slash home.

01:23.850 --> 01:24.780
Slash pi.

01:24.810 --> 01:26.340
Here again we use the absolute path.

01:26.370 --> 01:26.550
Okay.

01:26.580 --> 01:28.500
It's better slash.

01:28.500 --> 01:30.300
And the file was named.

01:30.300 --> 01:34.050
So file to join.

01:34.080 --> 01:35.220
Dot txt.

01:35.580 --> 01:37.380
So make sure you put the correct path.

01:37.380 --> 01:38.670
Then we close the parenthesis.

01:38.700 --> 01:38.880
Okay.

01:38.910 --> 01:41.940
So now we have two subject contents and attachments.

01:41.970 --> 01:43.380
And that's the same thing okay.

01:43.410 --> 01:45.180
We don't change anything else in the code.

01:45.210 --> 01:50.340
Let's uh run that actually let's just change the subject here.

01:51.360 --> 01:53.100
Second email for example.

01:53.100 --> 01:54.480
Let's send that.

01:55.470 --> 02:03.810
So you see email sent after a few seconds and I am back to my personal email inbox.

02:03.810 --> 02:10.020
And you see I have a new email here from Raspberry Pi at gmail.com.

02:10.020 --> 02:16.800
With the second email subject we have hello from Raspberry Pi and we have a file here, so file to join

02:16.800 --> 02:17.580
dot txt.

02:17.610 --> 02:23.850
If I open that one I can see a preview and you see this text file has been created on the Raspberry

02:23.850 --> 02:24.210
Pi.

02:24.210 --> 02:29.250
So now you know how to send an email and also send files with this email.

02:29.250 --> 02:34.020
And that's the end of this section with the Python and Terminal basics that you got already.

02:34.020 --> 02:39.480
You can see that sending an email with a Python module is really not that hard, and you can replicate

02:39.480 --> 02:42.060
that for any of your future projects.
