# Email Node In - Search for String

**URL:** <https://discourse.nodered.org/t/email-node-in-search-for-string/18955>\
**Category:** General\
**Created:** [9 December 2019 17:21 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955 "2019-12-09T17:21:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gc5lear](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@Gc5lear](https://discourse.nodered.org/u/Gc5lear)\
**Post date:** [9 December 2019 17:21 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/1 "2019-12-09T17:21:16Z")

</div>

Hi all, I’ve installed Hassio and Node Red today and what I want to do seems simple enough in theory but can’t find an obvious answer anywhere online.

I managed to create an email in and out node and the work just fine, I’m not expert with any of this so please be kind as I’ve seen techy forums before and they can be quite rough, all I want is this:

“If the email in the inbox contains “FIRE ALARM” in the body, do something, anything else leave as unread”

I have it working with all unseen mails but I only want unseen ones containing the above string.

I’m not experienced enough to translate git documents and just go ahead and configure them. _queue abuse_ so would really appreciate a bit more guidance on how I achieve this.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 December 2019 18:25 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/2 "2019-12-09T18:25:05Z")

</div>

have you tried using the `switch` node and the `contains` option?

---

<div class="post-metadata">

**Author:** ![Gc5lear](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@Gc5lear](https://discourse.nodered.org/u/Gc5lear)\
**Post date:** [9 December 2019 21:07 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/3 "2019-12-09T21:07:55Z")

</div>

Managed to get it to change the payload but I guess I still need something different. Is there a way to do an IF statement to say “if “FIRE ALARM do THIS, else BREAK” type thing? If it’s using js would be great if someone could share. The result of the hangs is that all inout email still hit my debug, only the payload is changed for matching emails.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 December 2019 21:38 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/4 "2019-12-09T21:38:38Z")

</div>

Is that using the Switch node as suggested?  
If you are using a Function node then show us the code you have already and explain in more detail what you are trying to do. What do you mean by BREAK in a function node? Do you mean that you want the function node to not pass on a message? If so then if you return null from the function node that tells it not to pass on a message.

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [9 December 2019 21:38 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/5 "2019-12-09T21:38:48Z")

</div>

> [@Gc5lear](#):
>
> “If the email in the inbox contains “FIRE ALARM” in the body, do something, **anything else leave as unread** ”

I think the above (bold) is not going to be easy to do with the standard email node, as the check on contents can only be done after the message has been received, and passed on for further processing. You can't go back and reset non-matching messages to "unread".

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [9 December 2019 22:05 UTC](https://discourse.nodered.org/t/email-node-in-search-for-string/18955/6 "2019-12-09T22:05:50Z")

</div>

You have not given us enough information here as to what email system you are looking at emails in.

Could i suggest a slightly different approach though

1. Use your email system (lets for the sake of the argument say Gmail) to setup some rules - so if the incoming email contains the key words (FireAlarm) in this case, then copy/move the email to a specific folder

2. Use the Email in node to just poll that specific folder for new incoming emails and then act on them in NR as you see fit

Craig
