To finish this quite quick section, we are going to see how to add an attachment to an email.
Okay, that's going to be very useful also for the final project of the course.
So we can send any file we want.
Let's make a quick test with just a text file that I'm going to create here on the Raspberry Pi.
So I open a new terminal and well let's create it in the home directory okay.
We can create a file with touch or directly with Nano because I'm going to write to it.
So nano file to join.
And let's add an extension okay dot txt because then if I open the email let's say on windows and I
download this file here and I want to open it, maybe it's going to be easier with a txt extension.
So nano file to join dot txt and let's write.
This text file has been created under Raspberry Pi okay.
You can write whatever you want Ctrl s Ctrl x.
Great.
Now we have our file here and how to send that file through email.
Well you just go back to the code.
Here we have two subject contents.
You're going to add a comma here.
Go back to a new line.
And we are going to put attachments okay.
With an S.
Then you are going to put an equal again and the path to the file.
So here.
Slash home.
Slash pi.
Here again we use the absolute path.
Okay.
It's better slash.
And the file was named.
So file to join.
Dot txt.
So make sure you put the correct path.
Then we close the parenthesis.
Okay.
So now we have two subject contents and attachments.
And that's the same thing okay.
We don't change anything else in the code.
Let's uh run that actually let's just change the subject here.
Second email for example.
Let's send that.
So you see email sent after a few seconds and I am back to my personal email inbox.
And you see I have a new email here from Raspberry Pi at gmail.com.
With the second email subject we have hello from Raspberry Pi and we have a file here, so file to join
dot txt.
If I open that one I can see a preview and you see this text file has been created on the Raspberry
Pi.
So now you know how to send an email and also send files with this email.
And that's the end of this section with the Python and Terminal basics that you got already.
You can see that sending an email with a Python module is really not that hard, and you can replicate
that for any of your future projects.