Send an email and include the current IP address

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?

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.

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

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.

    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.

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?

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

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

ipa

IP

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

1 Like

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.

If it's a public IP address (which 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...

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.

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.

You know what they say about assumptions :grinning:

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