And now, finally, we can actually use the YAML module to send our first email from the Raspberry Pi.
So there was a bit of setup, but after this setup, well, you will be able to send emails very quickly
and very easily.
I'm going to keep this code here with the password okay.
And what I will do at the beginning of the program is to first import the import Yaghmaian.
It's going to do that, and I make sure I go back to the previous indentation here.
And so to send an email you first need to create an email client okay I'm going to create that inside
a variable.
I'm just going to call it YAG is equal to your gmail dot.
And then SMTP all uppercase.
And you're going to open and close the parentheses.
And here you need to give two things.
First the email address that you want to send from and then the password.
So that's going to be the app password.
Once again it's not the password of the Google account.
It's the app password.
So for me it's course cool that Raspberry Pi at gmail.com, so make sure you put your email address
instead the one that you have created.
And then I put the password variable that I have just created in the last lesson.
Now I can send an email.
So I'm going to do.
Yeah.
So that's my Gmail client dot send as simple as this.
And I will need to provide a few arguments.
And for those arguments I first need to provide the name of the argument like this.
So two and then equal.
And I put some quotes.
So this is the email address that I want to send to here I'm going to put my personal email address.
Okay.
So I don't show you of course because it's my personal address.
And that's where I want to receive the emails from the Raspberry Pi.
I'm going to put a colon and then I go back to a new line with enter.
You can see that when I go back to a new line, it's automatically indented here.
You don't really need to do that, but it's just better for readability.
Okay.
And instead of adding all the arguments here to the same line, which is going to be very long, you
can add one per line, it's easier to read.
So we have two.
Then we will have subject equal okay.
So the subject of the email let's say first email I put a comma, go back to a new line and then contents
with an S is equal to.
And that's going to be the content of the email.
Let's say hello from Raspberry Pi.
And that's it for now.
So I'm going to close the parentheses okay.
We have two subjects and contents.
Then I go back to a new line actually that's it okay.
The code is finished.
You can send with that.
I'm just going to add a print email sent okay.
Just so we have an output in the program.
Otherwise you will run it and you will see nothing.
So let's run that.
okay.
It's taking.
Well, it took me 1 or 2 seconds and then you see email sent just to show you if, for example, I put
a wrong email address or a wrong password, if I try to run it, we should have an error like this.
Okay.
So username and password not accepted.
Okay.
So if you have this error make sure that you have put the correct email address.
And if this is correct then make sure that you correctly read the password okay from the file and that
everything is correct.
So you might need to go back also to your Google account.
Maybe create a new app password.
Just make sure that you have the correct combination.
So I am now seeing my email inbox.
So that's the email.
So that's my personal email right.
So I used the Raspberry Pi email to send to my personal email.
And I have received a new email you see from course dot Raspberry Pi at gmail.com.
So I'm going to open that.
And you see the subject is first email and we have the content.
Hello from Raspberry Pi.
So it correctly worked.