# Send an email and include the current IP address

**URL:** <https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091>\
**Category:** General\
**Created:** [19 September 2020 18:33 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091 "2020-09-19T18:33:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)\
**Post date:** [19 September 2020 18:33 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/1 "2020-09-19T18:33:23Z")

</div>

Hello,  
I have built in an email alert in Node Red that if a certain value is exceeded I get a mial. Now I would like to transfer my IP address so that when the mail arrives I just have to click on a link with the IP and the Node Red Dashboard opens. How can you solve this problem?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 September 2020 18:47 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/2 "2020-09-19T18:47:50Z")

</div>

Well firstly we need some additional info.

When you receive the email and act on it, will you still be on the same network as the Node-RED server?

If not, then the task is rather more complex than you may think.

If you are on the same network, all you need is the _external_ address of your Pi, the one that is probably something like `192.168.nnn.nnn` or `10.nnn.nnn.nnn`. The best thing to do is to fix the IP address of the Pi so that you can simply build that into the link you create.

---

<div class="post-metadata">

**Author:** ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)\
**Post date:** [19 September 2020 19:00 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/3 "2020-09-19T19:00:47Z")

</div>

Thank you for your prompt reply.

here is an excerpt from ifconfig:

pi@raspberry:~ $ ifconfig  
Braun-wg0: flags=209\<UP,POINTOPOINT,RUNNING,NOARP\> mtu 1280  
inet 10.8.0.7 netmask 255.255.255.0 destination 10.8.0.7

I would like the IP address to be read out by the Braun-wg0 adapter (in this case 10.8.0.7) and that I can send this address + ": 1880 / ui" via the Node function as an e-mail. In the Node function, which sits in front of my email node, some values ​​are already being transmitted, but now the IP address is not faulty

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 September 2020 19:20 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/4 "2020-09-19T19:20:59Z")

</div>

Node.js has a function that will tell you the current IP address. Can't remember what it is off the top of my head but you will find it in the docs. I use the `settings.js` file to put things like that into global variables so that I can use them in Node-RED flows.

```auto
    functionGlobalContext: {
        pid: process.pid,
        _env: process.env, // Pass environment vars to Node-RED
        userid: process.env.user || process.env.username,
        userHome: process.env.home || process.env.userhome,
        require: require, // DANGER Will Robinson!
        //_: require('lodash'),
    },

```

I don't save the IP address because my devices always have fixed addresses so I know them.

---

<div class="post-metadata">

**Author:** ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)\
**Post date:** [20 September 2020 12:15 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/5 "2020-09-20T12:15:31Z")

</div>

I understand what you mean....  
I could also save the fixed IP address directly as a global variable and then call it up again via the function node and send it by mail.

> process.env.IP = '10.8.0.7:1880/ui';

how can I then call up the value again in the node function?

> msg.payload=$(IP)

is that how it works?

---

<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:** [20 September 2020 14:58 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/6 "2020-09-20T14:58:28Z")

</div>

The node red docs page Writing Functions tells you how to do that if I remember correctly.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2020 15:34 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/7 "2020-09-20T15:34:51Z")

</div>

> **[Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)**

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [20 September 2020 15:53 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/8 "2020-09-20T15:53:31Z")

</div>

Plan B could be to use [https://www.ipify.org/](https://www.ipify.org/) to get your current IP address.  
Using a `http request` node, make a `GET` request to [https://api.ipify.org/](https://api.ipify.org/) and it will output your current IP address for the machine making the call.

![ipa](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46618721a340184b81323bd00af7b32560108b53.jpeg)

![IP](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e311b395d32062e5cb38bcf6acb40f6a95d96ff.jpeg)

You wouldn't need to save it as a global variable, just have one flow (add a template node to format your message & url);

`Temp over value flow` =\> `http request` =\> `template node` =\> `email node`

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 September 2020 22:38 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/9 "2020-09-20T22:38:53Z")

</div>

> [@Paul-Reed](#):
>
> current IP address

That will, of course, tell you your Internet address which comes back to my previous point. You need to know whether the recipient of the email will access the link on the same network as the Node-RED server or not.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [20 September 2020 22:49 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/10 "2020-09-20T22:49:18Z")

</div>

> [@TotallyInformation](#):
>
> You need to know whether the recipient of the email will access the link on the same network as the Node-RED server or not.

If it's a public IP address (which [ipify.com](http://ipify.com) will provide) it surely doesn't matter.  
I'm assuming that @volker1078 is receiving the email from his own system, when he's away from home, and outside his private network (that's why he wants to receive a email alert?).  
I could of course be wrong...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 September 2020 00:08 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/11 "2020-09-21T00:08:52Z")

</div>

> [@Paul-Reed](#):
>
> it surely doesn't matter

Surely it does?

If it uses an external address, clicking on the link when on the local network means that the link goes out to the Internet and back in again. Unless an incoming link has been set up, it won't work. If an external inbound connection is set up, you have the usual security issues to deal with. The whole setup is significantly more complex.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [21 September 2020 08:10 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/12 "2020-09-21T08:10:32Z")

</div>

> [@TotallyInformation](#):
>
> clicking on the link when on the local network means that the link goes out to the Internet and back in again

Yes, but as I said, I'm assuming that the OP will not be at home, and therefore will not access to his local network.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 September 2020 09:01 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/13 "2020-09-21T09:01:57Z")

</div>

You know what they say about assumptions 😀

---

<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:** [5 October 2020 09:02 UTC](https://discourse.nodered.org/t/send-an-email-and-include-the-current-ip-address/33091/14 "2020-10-05T09:02:09Z")

</div>

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