00:00
once you've installed and configured
00:02
your groov I/O nodes for the first time
00:03
you're ready to start doing something
00:05
more substantial with your data
00:07
if you haven't already installed these
00:08
nodes set up a localhost device and
00:10
gone over how to configure these go
00:12
ahead and watch our previous video
00:14
in this video i'll be reading in a
00:16
button on module 0 channel 0
00:18
and using that button press to trigger
00:20
an email that will send out whenever the
00:22
state changes
00:28
now your trigger doesn't necessarily
00:30
have to be this button press that i'm
00:32
going to be reading in
00:33
so you can use whatever you want there
00:35
just make sure that you have something
00:36
to trigger the flow so that it knows
00:38
when to send the email
00:39
the next thing is to of course install
00:41
the Node-RED email nodes
00:43
since you'll notice they're not included
00:44
with the core nodes that come
00:45
pre-installed with Node-RED
00:47
to do that i'll need to come up to the
00:49
menu in the top right and select manage
00:51
palette
00:52
i'll need to have an internet connection
00:54
to be able to install the nodes
00:55
but since i'm already connected to
00:56
ethernet I can just search email
00:59
and this is the one I want right here
01:01
Node-RED node email
01:02
so i'll just go ahead and select install
01:05
confirm the installation
01:06
and then I can click view log to see
01:08
that it's coming down
01:10
now depending on what version the node
01:12
is at and what version of Node-RED
01:14
you're running
01:14
you might see some warnings here but as
01:16
long as we get a return code of zero
01:18
and see the nodes added to our palette
01:20
everything will work okay
01:21
so just sit and wait for them to finish
01:24
installing
01:26
there we go after just a couple of
01:27
seconds of waiting we can see that we
01:29
have this return code of zero
01:31
we have this green pop-up confirming
01:32
that the nodes are added to our palette
01:34
so i'll just go ahead and close out of
01:36
this and there we go we can see we have
01:37
a new social tab here
01:39
with our Node-RED emails coming in and
01:41
to send emails with this bottom node
01:43
here
01:44
so i'll just drag one in and we'll
01:45
select it so that we can see how to
01:47
configure this in the info tab
01:49
so we can see here the body of the email
01:51
needs to go in message.payload but the
01:53
subject goes in message.topic
01:55
there are some other properties you can
01:57
use here like message.2
01:59
cc and bcc to determine who receives the
02:02
message if you want to send it to
02:04
more than one person or even an entire
02:05
team or
02:07
if you double click the node you can see
02:08
that the recipient can be configured
02:10
statically inside the node
02:11
this is what i'm going to do so i'll
02:13
send it to myself developer
02:16
at opto22.com
02:20
but when I come down here for my user id
02:22
i am not going to use that same personal
02:24
account
02:25
the reason for that is I am going to
02:26
have to add an application password to
02:28
enable Node-RED to access my account
02:30
and read my emails I want to keep this
02:33
separate from my personal account so
02:34
i've created a new email
02:36
optoalerts
02:39
gmail.com now I am going to try first
02:42
logging in with my regular password and
02:44
that's not going to work because it's
02:46
not an application password
02:47
i'm going to put it in anyway so we can
02:49
see what happens and what we need to
02:51
change to make it work
02:52
now i'll give this node a name like send
02:54
email and we'll go ahead and configure
02:57
how we're going to write the email
02:59
because we're just reading in an input
03:01
here true or false
03:02
we want to turn that into an actual
03:04
email body and set all the different
03:05
properties we need
03:07
to do that I could use a change node up
03:09
here and set the properties individually
03:11
but i'm going to use a function node so
03:13
we can do some more intense processing
03:15
so i'll just wire that in make sure it's
03:18
wired in and double click it to
03:19
configure it
03:21
here i'm going to be writing the email
03:23
and so
03:24
i will need to set my properties for
03:26
example I can set my message.topic
03:28
to be the the button
03:32
has been turned on
03:36
and then I could send some kind of
03:37
payload like message.payload
03:40
equals the button was
03:43
turned on at and then I just want to add
03:46
a nice simple
03:47
date string so I know exactly when it
03:48
was toggled to do that I can just say
03:51
new date dot to string
03:57
this will give me a nicely formatted
03:59
date that gives me all the information i
04:00
need
04:01
now again I could do message.2 and set
04:04
some
04:05
recipient at mail.com
04:09
and add some others here as well but
04:12
like you saw before i'm going to be
04:13
using the static settings in the node i
04:15
just want you to know what that looks
04:16
like
04:17
now because this message is for when it
04:19
was turned on I can also add another
04:21
message from when it gets turned off
04:23
all we need to do is check if
04:25
message.payload
04:27
is equal to true we want to set the
04:30
properties to be these
04:35
otherwise or else i'm going to make a
04:38
copy of those
04:39
and just change the text to say that it
04:41
got turned off
04:44
now I will get two separate emails based
04:46
on whether the
04:47
incoming topic is true or
04:51
if it's false now these two different
04:53
parts will give me two separate emails
04:54
so I know the actual
04:56
value of it not just that it's been
04:57
toggled but how it's been toggled
04:59
so now that I know my email is written i
05:01
can just click done
05:03
we'll see the email come out and we also
05:05
want to see it in the debug pane
05:06
so i'll press and hold left ctrl and
05:08
left click on my workspace
05:10
just to quickly drop in this debug node
05:12
but I want to see more than just this
05:14
message.payload that's the email body
05:16
i want to confirm that my subject is
05:18
correct as well so
05:19
i'll double click this node and switch
05:21
it from message.payload to show the
05:23
complete message
05:23
object now when I hit done and wire that
05:26
in I know i'll see everything over here
05:28
in the debug pane
05:30
now I can go ahead and deploy we'll see
05:33
that the button has come in
05:34
and it comes in as turned off because
05:36
currently the state is false and we want
05:37
to alert them of the current state
05:39
but i'm getting this invalid login that
05:41
my password is not being accepted
05:44
that's because i'm using my standard
05:45
login not that application password i
05:47
was talking about before
05:49
now let's head over to the other gmail
05:51
account and see how to configure that
05:53
so in my other gmail i'll just come up
05:55
and select settings
05:57
and come over here to manage your google
05:59
account
06:01
you'll need to come over to the security
06:02
section to get to the application
06:04
password
06:05
and then we can come down and see that
06:06
my two-step verification is turned off
06:09
and that I do not have less secure app
06:11
access enabled
06:13
now right now I could turn insecure app
06:16
access on
06:17
and allow Node-RED to use my password
06:19
that way but this method is not
06:20
recommended by google and it is going to
06:22
be phased out in the not too distant
06:24
future
06:24
so rather than taking this route i'm
06:26
going to come up and i'm going to add
06:28
a two-step verification so that I can
06:30
create an application password
06:32
you can't create an application password
06:34
without two-step verification
06:35
so you will need to go through this
06:37
process i'll select this
06:39
click get started and I will have to put
06:41
in my user password again
06:45
now that i'm logged in I will need to
06:47
put in either a phone number to get my
06:49
text message or phone call to confirm
06:51
that this is in fact my account
06:53
i'm not going to show you what I put in
06:54
because it's going to be my phone number
06:56
but this process is very straightforward
07:00
now that i've confirmed my two-step
07:01
verification I can go ahead and turn on
07:04
the feature so now that the feature is
07:07
turned on i'll go back to the main menu
07:10
and we can see now I have the option to
07:11
create app passwords where currently
07:13
i have none so again I just log into my
07:16
account with my usual password
07:19
and here I can create entirely new
07:21
applications i'll create a custom one
07:23
just for Node-RED
07:26
now when I click generate i'll get this
07:28
password generated here
07:30
this password is going to be different
07:31
for every app you create and it'll be
07:32
different for every account
07:34
so obviously this code won't work for
07:36
you i'll just copy that to my clipboard
07:38
hit done and then we'll bring this back
07:40
to Node-RED
07:43
now here in Node-RED I just double-click
07:45
the email node
07:46
i replace that old login password and
07:48
paste in my new application password
07:51
and click done
07:54
so now when I click deploy we'll get
07:56
that first off status come in the
07:58
current state of the button and in fact
08:00
we do get the topic
08:01
the button has been turned off and no
08:02
errors from the email node
08:04
so now if I bring open my email we can
08:07
see there we go the button was turned
08:09
off and the timer was toggled off
08:11
if I go back to Node-RED and toggle the
08:13
button on we'll get another email
08:15
this time saying that the button has
08:16
been turned on and go back to my email
08:20
we'll see there we go we have another
08:21
message saying that the button has been
08:23
turned off
08:24
so now we're getting appropriate message
08:26
subjects and appropriate message bodies
08:28
that include
08:28
useful information like the current time
08:30
that the button was toggled
08:31
and it's all coming through this nice
08:33
easy flow here
08:34
in future videos i'll show you how to
08:36
receive emails into Node-RED
08:38
or how to send emails with attachments
08:40
thanks for watching