Feature request: Embed images into email

Heyup,

Would it be possible to have images embedded into the emails, using base64 or something, so that images can be loaded irrespective of connection used (At the moment I have it restricted to local VPN range only). However, this isn’t ideal.

I hope I’ve described this well enough…

Cheers

EDIT: Can’t be in data:uri format, otherwise gmail webmail will reject the images.

https://github.com/librenms/librenms/issues/3192

2 Likes

This would be an awesome addition.

I made a pull request for this yesterday

If you want to help test,
./scripts/github-apply 8646

Add this line somewhere in your config.php
$config['allow_unauth_graphs'] = true;

Add this line in your HTML template and change the alt value to your graph.
<img width="800" height="300" src="cid:embedimage" alt="https://SERVERIP/GRAPHLINK">

1 Like

That’s fine if your LibreNMS is accessible from the internet - a better fix would be to somehow embed/attach the actual graphic generated by the graph URL - I realise this would be a snapshot in time of the graph, but better than the current state of affairs.

1 Like

This is what the pull request is for, embeds it into the email. Useful for those where your email client doesn’t have access to the LibreNMS instance.

I believe this issue is to attach an image in the email that is a snapshot in time. That way you can see the image if you can’t access the server.

Am I correct that your PR still needs access to the server to display the image? We can currently do images with HTML alerts but that isn’t ideal. Many don’t want to connect to a VPN to see the graphs.

I see you said that’s what the pr does. I guess I’m confused on why allow_unauth_graphs is needed then?

Can you explain further?

it attaches it on the server side before the email is sent , so theoretically you could start the link with https://127.0.0.1/graph.php etc . The server is still trying to access the link which is protected by LibreNMS auth just like on normal LAN.

The email is then sent off with the attached image (not linked) .

You could lock down unauth to be allowed on the server only, $config['allow_unauth_graphs_cidr'] = array('127.0.0.1/32');

1 Like

So I tested it, my librenms server is on local lan network,it is not accesible from the internet, only from local network. We have our own mail server, I am using smtp in email transport througt our own mail server, which is in DMZ, so i have real email address in our mail server which i using to send email to whatever email. I had a problem with sending graphs to email, but now i am using @chas PR with $config['allow_unauth_graphs'] = true; and this link in my html emails.: <img width="800" height="300" src="cid:embedimage" alt="https://SERVERIP/GRAPHLINK">

In real life it is looking something like this: (I edited it to english for you), but in real life I am using Slovak Language

<div style="font-family:Helvetica;">
<h2>{if %state == 1}<span style="color:red;">Warning{/if}
{if %state == 2}<span style="color:goldenrod;">Planned load{/if}</span>
{if %state == 3}<span style="color:green;">It is recovering{/if}</span>
{if %state == 0}<span style="color:green;">Recovered{/if}</span>
</h2>
<b>Hostname:</b> %hostname<br>
<b>Limit:</b> 80 %<br>
<b>CPU Load Length:</b> %elapsed<br>
<br>
<b>Graph for the last hour:</b><br>
<img width="700" height="300" src="cid:embedimage" alt="http://myserver/graph.php?&type=device_processor&lazy_w=805&device=%hostname&?=yes&height=486&width=1656&from=end-1h">
<br>
<b>Click to enlarge::</b> http://myserver/graphs/type=device_processor/legend=yes/lazy_w=729/device=%hostname/
<br>
<br>
<b>Faults:</b><br>
{if %faults}                                                                                    
{foreach %faults}#%key: %value.string<br>                                                              {/foreach}                                                                                                             
{/if}
</div>

and in email for example, I am tested it into gmail for example, where it is working the best, because I can click on that graph and zoom it, but it is working great with my mail address from the our mail server too. In outlook was the problem with spam assasin, but when i added mail addres to the whitelist in my mail server it is working great.

And here is the final email html alert. (In Slovak language, sorry)

So @Chas thank you for that PR, it is working correctly finally from whateever network, where I am connected.

2 Likes

Thats awesome @dohlad thanks to help test it :smiley:

1 Like

Awesome Chas! I will try to make some time to test this.

I wasn’t overly worried about unauth graphs, but locking it down to localhost is even better.

1 Like

It appears if using Outlook at as mail client (I know, don’t judge me) that if you have the graph type set to SVG it doesn’t work. Setting to PNG allows it to work.

In gmail it is same with SVG

I just added logic for SVGs in my latest commit, you may need to run ./scripts/github-apply 8646 again to get the latest code, it works in office365, but for some reason it attaches it also.

It may not work in your email client if you choose SVG format. Apparently it’s a bit hit and miss.

See: https://stackoverflow.com/questions/32981760/is-there-a-trick-to-display-svg-images-in-gmail

I recommend png for email client support and the file size is 90kb~ lower.

Seems to work - albeit with spotty mail client support for SVG. 90kB is a rounding error these days - I remember when it was over half a floppy disc though :wink: