# Ui-switch node and e-mail

**URL:** <https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390>\
**Category:** General\
**Tags:** node-red-dashboard, function-node\
**Created:** [18 December 2021 13:37 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390 "2021-12-18T13:37:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gytomig2](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gytomig2](https://discourse.nodered.org/u/gytomig2)\
**Post date:** [18 December 2021 13:37 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/1 "2021-12-18T13:37:06Z")

</div>

Hello, I'm using (v1.3.5) of system.  
I have built a room temprature indicator.  
I would to use e-mail notification according to the switch is on.  
The e-mail sending is working correctly.  
I just can't create the switch related sending method.  
Please help to solve this problem.

 ![Node_Red question v01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71d99125b5fe27166c28522d82284a657b4184d1.jpeg)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [18 December 2021 15:07 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/2 "2021-12-18T15:07:42Z")

</div>

Welcome to the forum @gytomig2.

One way to do it would be for the function node to set a context variable according to the output from the switch `flow.set('sendemail', "YES")` or` flow.set('sendemail', "NO")`

Then the switch node before email can test the value of flow.sendemail.

---

<div class="post-metadata">

**Author:** ![gytomig2](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gytomig2](https://discourse.nodered.org/u/gytomig2)\
**Post date:** [18 December 2021 16:36 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/3 "2021-12-18T16:36:47Z")

</div>

Thank you 'jbudd' your answer.  
Sorry but it is not easy to me.  
My target is the next:  
If the room temperature less than 19 °C or higher than 21 °C I need an e-mail message.  
But when I read the e-mail I would to stop the automatic e-mail sending with a switch (for example).  
I'm a programmer (visual basic, Java, LabView, etc.), but unfortunately this NodeRed logic is new for me.  
I have to catch this kind of logic method, but it comes slowly 🙂

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [18 December 2021 16:50 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/4 "2021-12-18T16:50:28Z")

</div>

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/c/cca2badad07caa996f9f23fabbfadff0fffdc264.jpeg "Node-Red -How to Send Email and SMS Notifications") ](https://www.youtube.com/watch?v=rokLM4ZsMJQ)

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/283fc9b51651cb00468a9ce0dc567a24672eb818.jpeg "Node-RED Tutorial: Email Alerts & Notifications") ](https://www.youtube.com/watch?v=qw3oKBp4rrQ)

these helped me a lot. may be it will to you too, give it a try

---

<div class="post-metadata">

**Author:** ![gytomig2](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gytomig2](https://discourse.nodered.org/u/gytomig2)\
**Post date:** [19 December 2021 13:04 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/5 "2021-12-19T13:04:03Z")

</div>

Thank you 'smanjunath211' and 'jbudd' the ideas.  
I used your recommendations and read some informations about the global variables.  
And voila the problem solved.

 ![Node_Red question v02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a6a444ecf08c27f7fb7b0c4d5a46675256b7086.jpeg)

```auto
var sendemail=global.get('sendemail') || "NO";
var switch1=context.get('switch1') || 0;
var topic=msg.topic;

if (topic=="s1")
{
    switch1=msg.payload;
}

if (switch1)
    global.set('sendemail', "YES");
if (!switch1)
    global.set('sendemail', "NO");

return msg;

```

![Node_Red question v02b](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cdb336b69c7cd082fa42428bd1067d19ebded74.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 February 2022 13:04 UTC](https://discourse.nodered.org/t/ui-switch-node-and-e-mail/55390/6 "2022-02-17T13:04:27Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
