# Using Node-RED IMAP email payload as an iOS notification

**URL:** <https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185>\
**Category:** General\
**Created:** [27 October 2019 01:45 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185 "2019-10-27T01:45:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![grantalewis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grantalewis/32/13645_2.png) [@grantalewis](https://discourse.nodered.org/u/grantalewis)\
**Post date:** [27 October 2019 01:45 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/1 "2019-10-27T01:45:35Z")

</div>

I use Node-RED in Home Assistant ([Hass.io](http://Hass.io) running in Docker on Ubuntu 64). My current project is to move all messages -- texts, emails, iOS notifications, etc. generated by the various components in my system -- to iOS notifications only.

My Leviton OmniPro II is configured to send all of its notifications to a dedicated Gmail address. I'm able to retrieve those emails in a Node-RED flow and would like to now send the payload on to a Call Service node that notifies my iOS device. Here are the results from the Node-RED email node:

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3e0852e68f0f489315d8b6da71afe41bb5304e5b.png)

```auto
[{"id":"16a60954.5e121f","type":"api-call-service","z":"d5b4d090.56c5e","name":"Notify iOS","server":"36944218.4145ce","version":1,"service_domain":"notify","service":"ios_grant_lewis_iphone","entityId":"","data":"{\"message\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":510,"y":120,"wires":[[]]},{"id":"5c57e0e9.9bba5","type":"debug","z":"d5b4d090.56c5e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":490,"y":80,"wires":[]},{"id":"e1f4beff.b431f8","type":"e-mail in","z":"d5b4d090.56c5e","name":"","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"port":"993","box":"INBOX","disposition":"Read","criteria":"UNSEEN","repeat":"30","fetch":"auto","inputs":0,"x":100,"y":80,"wires":[["5c57e0e9.9bba5","16a60954.5e121f"]]},{"id":"36944218.4145ce","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

```

As the above shows, there's something about the payload that's causing an API error. I've exhausted every avenue I can find -- change nodes, function nodes, etc -- trying to solve the problem, all without success. Any insight woudl be very much appreciated.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 October 2019 03:20 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/2 "2019-10-27T03:20:09Z")

</div>

This is an error coming from home assistant, not node-red.  
Somewhere in your yaml configuration (email?) you either have a typo or misconfigured something.

---

<div class="post-metadata">

**Author:** ![grantalewis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grantalewis/32/13645_2.png) [@grantalewis](https://discourse.nodered.org/u/grantalewis)\
**Post date:** [27 October 2019 10:47 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/3 "2019-10-27T10:47:25Z")

</div>

I send notifications to my iPhone multiple times a day:

```auto
[{"id":"9df28333.e5e6","type":"inject","z":"3750e6ca.390e4a","name":"ON","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":1300,"wires":[["1fc44014.376d28"]]},{"id":"1fc44014.376d28","type":"api-call-service","z":"3750e6ca.390e4a","name":"Notify Grant","server":"36944218.4145ce","version":1,"service_domain":"notify","service":"ios_grant_lewis_iphone","entityId":"","data":"{\"message\":\"Test iOS notification from Node-RED.\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":250,"y":1300,"wires":[[]]},{"id":"36944218.4145ce","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

```

Configuration is automatic. When a device connects to HA using the HA app for iOS, it appears an entity automatically. As long as the user permits notifications in the app, then a simple call service to that entity is all it takes.

The only difference in this case is that the payload I'm trying to send is generated, not static. So it's the payload that's the problem.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [27 October 2019 10:59 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/4 "2019-10-27T10:59:12Z")

</div>

It doesn’t look like it’s the payload, as the one you show shows a simple string.

Try changing your debug node to display the entire message

---

<div class="post-metadata">

**Author:** ![grantalewis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grantalewis/32/13645_2.png) [@grantalewis](https://discourse.nodered.org/u/grantalewis)\
**Post date:** [27 October 2019 11:03 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/5 "2019-10-27T11:03:34Z")

</div>

Incidentally, the same thing happens with this scenario:

- create a sensor in yaml to retrieve emails
- retrieve the results of that sensor with a Current State node
- use the **data.attributes.body** portion of the payload as an iOS notification

yaml:

```auto
  - platform: imap_email_content
    server: imap.gmail.com
    port: 993
    username: !secret gmail_notify_username
    password: !secret gmail_notify_password
    folder: INBOX

```

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8a1276e55937c08d8330df34c9d21e5bc96fb4a6.png)

```auto
[{"id":"fb30e5a0.396e48","type":"api-current-state","z":"d5b4d090.56c5e","name":"IMAP Sensor","server":"36944218.4145ce","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.3560lewishome_gmail_com","state_type":"str","state_location":"","override_payload":"msg","entity_location":"","override_data":"msg","blockInputOverrides":false,"x":150,"y":140,"wires":[["2bdd6ba0.cf6424"]]},{"id":"4d92336a.b017e4","type":"inject","z":"d5b4d090.56c5e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":80,"wires":[["fb30e5a0.396e48"]]},{"id":"5c57e0e9.9bba5","type":"debug","z":"d5b4d090.56c5e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":140,"wires":[]},{"id":"2bdd6ba0.cf6424","type":"change","z":"d5b4d090.56c5e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.body","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":140,"wires":[["aa29eceb.773758","5c57e0e9.9bba5"]]},{"id":"aa29eceb.773758","type":"api-call-service","z":"d5b4d090.56c5e","name":"Notify iOS","server":"36944218.4145ce","version":1,"service_domain":"notify","service":"ios_grant_lewis_iphone","entityId":"","data":"{\"message\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":550,"y":180,"wires":[[]]},{"id":"36944218.4145ce","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

```

So again, it seems there's something about the payload that's causing the error.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 October 2019 11:15 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/6 "2019-10-27T11:15:35Z")

</div>

The HA node rejects the data, it is homeassistant.

Change your debug node to display "complete msg object"

---

<div class="post-metadata">

**Author:** ![grantalewis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grantalewis/32/13645_2.png) [@grantalewis](https://discourse.nodered.org/u/grantalewis)\
**Post date:** [27 October 2019 11:19 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/7 "2019-10-27T11:19:16Z")

</div>

Thanks to both @bakman2 and @ukmoose for the replies.

Here's the revision:

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/67d3f787302614e5e7ed48f2d0876f3e2f4433c5.png)

```auto
[{"id":"aa29eceb.773758","type":"api-call-service","z":"d5b4d090.56c5e","name":"Notify iOS","server":"36944218.4145ce","version":1,"service_domain":"notify","service":"ios_grant_lewis_iphone","entityId":"","data":"{\"title\":\"Update\",\"message\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":370,"y":160,"wires":[[]]},{"id":"b0821272.332b38","type":"debug","z":"d5b4d090.56c5e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":350,"y":100,"wires":[]},{"id":"d8f0441d.a55758","type":"e-mail in","z":"d5b4d090.56c5e","name":"","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"port":"993","box":"INBOX","disposition":"Read","criteria":"UNSEEN","repeat":"30","fetch":"auto","inputs":0,"x":80,"y":100,"wires":[["b0821272.332b38","aa29eceb.773758"]]},{"id":"36944218.4145ce","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

```

In this case the path appears to be just **payload** , right?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 October 2019 11:23 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/8 "2019-10-27T11:23:57Z")

</div>

You set `msg.payload` to `msg.data.attributes.body` in the change node, but there is no `msg.data.x` in `msg.payload`.

> - use the **data.attributes.body** portion of the payload as an iOS notification

Perhaps you configured the change node in reverse; do you want to set a property `.data` ? If so, change the change node. (set `msg.data.x` to `msg.payload`) The change node can be confusing if you work with payload properties. The hint is: `set`, meaning - a new property.

---

<div class="post-metadata">

**Author:** ![grantalewis](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grantalewis/32/13645_2.png) [@grantalewis](https://discourse.nodered.org/u/grantalewis)\
**Post date:** [27 October 2019 11:42 UTC](https://discourse.nodered.org/t/using-node-red-imap-email-payload-as-an-ios-notification/17185/9 "2019-10-27T11:42:46Z")

</div>

My apologies. Trying to save time I inadvertently used an old screen shot with new code. I had been experimenting (unsuccessfully) with the change node while tinkering with the IMAP yaml process. I removed it in later attempts since it didn't seem to be helping. It was in that IMAP process that the path I mentioned appeared.

HOWEVER... in the process of creating a new example to use for this reply, I may have fixed whatever goof that was causing the problem.

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e58c24786a2c8b63f0afcd0d3a17878f2b765506.png)

I just received an iOS notification of the test message I sent, so you were right -- it evidently WAS something I'd mistyped.

I'm a little embarassed, but thank you for the hand-holding.
