Hi,
Currently i’m busy with getting the template working by attaching a graph image to an email.
The thing is that when i’m at home and see a CPU alert in my inbox, it would be great if i can see a CPU graph.
So I after searching on the interweb, i came across this post: https://community.librenms.org/t/feature-request-embed-images-into-email/. When reading it, i saw that Dohald and Chas make it work; i then went to GitHub and looked at the specific PR 8646, i attached the code from here: https://github.com/librenms/librenms/pull/8646/files#diff-f81f3dff36bf04b7a070d642c858e883 into the functions.php.
$mail->Body = $message;
if ($html) {
$mail->isHTML(true);
//Addding functionality to support cid embedded graphs
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
"timeout" => 1200,
),
);
preg_match_all('/ alt=\"(.*?)\"/', $mail->Body, $match);
$countcheck = 0;
$newcidhtml = $mail->Body;
foreach ($match[1] as $item) {
$newcidhtml=preg_replace("/\bembedimage\b/i", $countcheck, $newcidhtml, 1);
$image = file_get_contents($item, false, stream_context_create($arrContextOptions));
if ($config['webui']['graph_type'] == 'svg') {
$mail->addStringEmbeddedImage($image, $countcheck, 'graph.svg', 'base64', 'image/svg+xml');
} else {
$mail->addStringEmbeddedImage($image, $countcheck, 'graph.png', 'base64', 'image/png');
}
$countcheck++;
}
$mail->Body = $newcidhtml;
}
switch (strtolower(trim($config['email_backend']))) {
case 'sendmail':
So far so good.
I then added this code to my template, based on the input from Dohald; that didn’t work either at first: <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">
I had to change the link in the alt; replacing the ampersand with slashes and i had to replace the cid:embedimage with cid:graph.png; after this, i could see the graph in my Outlook 2016 client.
<img src="cid:graph.png" alt="https://monitor.domain.nl/graph.php/device={{ $alert->device_id }}/type=device_processor/width=800/height=300/lazy_w=552/from=end-1h">
But now i wanted also it viewable in my native IOS mail app, and there i’m stuck; the graph doesnt show; it is just a blank square; i even can’t see the alt text within it; so it looks like it is loaded, but on the otherhand it is not.
Anybody idea’s how to fix this?