New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How can I send custom HTML email notifications?

Votes:

0

Your Vote:

Up

Down

With recent versions, the customized HTML email notifications have been removed from PRTG. But I need that feature! Is there any way to bring it back?

custom-html email-notifications emails html notifications placeholders prtg

Created on Jan 28, 2016 11:29:42 AM by  Stephan Linke [Paessler Support]

Last change on Feb 3, 2016 7:36:50 AM by  Stephan Linke [Paessler Support]



20 Replies

Accepted Answer

Votes:

4

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 15.4.21 or later

Custom HTML Email Notifications

Recently, we changed the way PRTG handles notification emails and simplified the approach so there is only one email template and the option to deliver plain text emails. For most of our customers this will be sufficient. But what about customers that have multiple clients and need customized notifications, languages, logos and layouts?

That's where this script can help. It allows you to create a template file structure with, for example, placeholders, graphs, and custom company logos. It uses a folder called custom (depending on the version, it must first be created manually) within the new \mailtemplates subfolder as of PRTG version 15.4.21. It also supports the use of PRTG groups as well as single email addresses. If PRTG groups are used, you can also decide if only the users primary addresses or every mail configured will be used.

Features

  • Template based HTML mailing
  • Custom logos for each template folder
  • Various placeholders including live graph and sensor stats for the email body and the subject
  • Primary and secondary email servers as fallback (including encrypted password storage)
  • Send emails directly to PRTG user groups without having to worry about their members
  • Send emails to all notification contacts of a user or only the primary one
  • Send emails to separate email addresses (separated by comma)
  • Email address sanity check (duplicate removal and syntactical check)
  • Verbose logging for error detection
  • Use different priorities

Note: This script and its functionality have been tested under PowerShell 4.0. Please make sure it is installed on the PRTG core server or remote probe system, depending on where you use the script.


How Do I Install the Script?

  1. Execute Set-ExecutionPolicy RemoteSigned in a PowerShell (x86) with administrative privileges on the PRTG core server or the remote probe system, depending on where the script is.
  2. Copy the script (located at the end of this reply) to
    C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE
  3. Modify the script parameters according to your environment. Enter, for example, email server addresses, paths, and account names.
  4. Call the script with the parameter -SetupPasswords. It will ask for the primary and secondary email server passwords. They are stored encrypted inside the same directory.
  5. Create a structure for your template folders under
    C:\Program Files (x86)\PRTG Network Monitor\webroot\mailtemplates\custom
    (For details, see appendix figure 1, template structure.)

So much for the basic installation. Now you can create a new notification with the following parameters: -SensorID %sensor -Recipients @("[email protected]","[email protected]") -prtgGroup "PRTG Users" -TemplateFolder "TemplateA" -Template "simple" -From "[email protected]" -Subject "[sensorPARENTDEVICE] [sensorNAME] Sensor is in sensorSTATUSTEXT state." -Priority "High" (can be low, normal or high. Default is high) -Placeholders @("Team","www.test.com") -PrimaryOnly

The script will now send mails to [email protected] and [email protected] as well as to the members of the PRTG user group PRTG Users. It will use the TemplateA folder and the simple.htm template located within that folder

Is There any Way I Can Test if the Script Is Working Properly?

The script has the verbose switch enabled by default (line 100). If everything is configured correctly, run the script on a command line with the parameters above, modified to your environment. It will look somewhat like this: HTMLNotify console output

The script is pretty chatty, so if something goes wrong, you should directly see the problem.

What About My Passwords? Are They Stored in Files?

Yes, your email server passwords will be stored in two encrypted files. The encryption is done with a separate key, so it is not bound to your user account and can be executed with every user account on the PRTG server. Make sure that only this very user account is allowed to read the key files. This will make your passwords be safer instead of just saving them as clear text.

How Do my Templates Have to Look? Can I Use Placeholders and Graphs?

There are multiple placeholders that you can use within the HTML file itself and the subject of the email address. They will be replaced automatically. Note that there are two types of placeholders:

  • Always present placeholders, taken from PRTG
  • Custom placeholders that you can pass via parameters.

The table itself can be found in the appendix, figure 2. You can use, for example, the current live graph, sensor stats, and messages. As for the additional parameters, they are passed to the script like this:

-Placeholders @("Tech Support Team", "https://www.paessler.com")

Within the template, they can be placed like this:


Dear {0},\\
<br /><br />\\
Please have a look at {1} - Thanks!\\
\\
Yours truly,
PRTG

...using numbers (starting at 0) encapsuled in curly brackets. After replacing, it will look somewhat like this:


Dear Tech Support Team,

Please have a look at https://www.paessler.com - Thanks!

Yours truly, PRTG


Note: The amount of placeholders in the template must match the placeholders passed to the script. Otherwise, you might get unexpected results.


How Does the Logo Placement Work Exactly?

Within the templates folder (or their subfolders), there has to be a file called logo.png that represents the template folder (for example, a customer's logo). If no logo is found in either folder, the Paessler logo will be used.

Do You Have an Example of a Filled HTML Template?

Please see appendix, figure 3, for a filled HTML template. Note that the template is just an example. Design it as you like. An example source code can be found over at pastebin: http://pastebin.com/k1mGBujz (courtesy of advancedrei)

Are There Schematics so I Can See Which Steps the Scripts Actually Take?

With large scripts comes great complexity. You can find the flowchart for the script in the appendix, figure 5.

Disclaimer

This script underwent testing, although we cannot make sure that all scenarios are covered. Usually, it is provided "as is". However, if you find any bugs or have improvements, please do not hesitate to share!

Appendix

1. Template Structure

FolderContent
TemplateAsimple.htm
detail.htm
temperatures.htm
logo.png
TemplateBdatabases.htm
temperature.htm
logo.png

2. Placeholders

PlaceholderReplaced by
miscLOGOThe template logo that resides in the template folder with HTML image tag.
sensorNAMEThe name of the sensor
sensorTYPEThe sensor type
sensorLIVEGRAPHCurrent live graph as HTML image tag
sensorSTATECOLORThe current state color, in hex form (#dedede)
sensorSTATEICONThe sensors current state icon (will be attached automatically)
sensorINTERVALThe current sensor interval
sensorPARENTGROUPThe sensors parent group
sensorPARENTDEVICEThe sensors parent device
sensorPARENTDEVICEIDThe sensors parent device ID
sensorLASTVALUEThe sensors last value
sensorLASTMESSAGEThe sensors last message
sensorSTATUSTEXTThe current status text of the sensor
sensorSTATUSIDThe status ID of the sensor
sensorLASTUPThe sensors last up time
sensorLASTDOWNThe sensors last down time
sensorLASTCHECKThe last check of the sensor
sensorUPTIMEUptime value of the sensor in percent
sensorUPTIMETIMEUptime in friendly format (e.g. 100 days)
sensorDOWNTIMEDowntime in percent
sensorDOWNTIMETIMEDowntime in friendly format
sensorUPDOWNTOTALCoverage in friendly format
sensorUPDOWNSINCECreation date of the sensor?
sensorURLThe URL of the sensor
deviceURLThe URL of its parent device.

3. A Filled Notification

HTMLNotify - a mailtemplate with variables filled

4. The HTMLNotify Script

Source at GitHub

5. Schematics

Schematics of HTMLNotify

Created on Jan 28, 2016 12:39:15 PM by  Stephan Linke [Paessler Support]

Last change on Nov 19, 2018 7:33:15 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I'm trying to use the PRTG placeholders in my custom HTML email template but they don't work. All i see in the email it the placeholder text (e.g %probe, %history %systemdatetime, etc...). Is there a special format needed?

snippet from my template: <td> <br><h3>History</h3>%history<br> </td>

Thanks

Created on Apr 25, 2016 3:40:16 PM by  lbquoc (0)



Votes:

0

Your Vote:

Up

Down

Can you post your parameter field of the EXE file (from the notification)? Is it possible that you didn't hand it over via -placeholders?

Created on Apr 26, 2016 6:17:45 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Wow this is sooooo complex. We use an email to SMS service so the message we get on the phone is just full of this at the beginning;

Sensor:

Almost useless. There isn't a simpler way to cut down the nonsense emailed to an sms gateway?

Joe

Created on Jul 31, 2016 10:34:52 PM by  joelions (0)



Votes:

0

Your Vote:

Up

Down

You could set the mail to text only in the notification options, then you can configure an entirely custom text :)

Created on Aug 1, 2016 6:26:37 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Have been able to get the script working via powershell, passing the parameters and receiving the email with the correct template. But when associating the powershell script in the notification settings and putting the same parameters under execute program it is not working. Have tried the execute program option to run the program under the local admin account and still didn't work. Is there a way for the script to generate a log to troubleshooting why it is not working with PRTG.

Created on Jan 27, 2017 7:44:13 PM by  afern (0)



Votes:

0

Your Vote:

Up

Down

Are you already using PowerShell sensors within PRTG? If not, you may need to work through step #1:
https://kb.paessler.com/en/topic/71356-guide-for-powershell-based-custom-sensors

Let me know if that's not the case or if it has worked :)

Created on Jan 30, 2017 6:23:59 AM by  Stephan Linke [Paessler Support]

Last change on Jan 30, 2017 6:24:07 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I don't see sensor comments as one of the placeholders that can be used.

We're wanting to just edit/customize the standard HTML notification mail to put the sensor comments higher (like right above the sensor status). This is mostly because we keep "how to fix this" notes in the comments, and want it more visible than having to scroll down past the graphs and so on.

If there's an easier way to do that than by making an all new custom template, that would be awesome too.

Created on Feb 2, 2018 3:40:22 PM by  jdsok (0) 1



Votes:

0

Your Vote:

Up

Down

You can sure use them. Assuming that it's your only placeholder, simply add {0} to the template and use the following parameters: -Placeholders @("%comments") This will replace {0} with the content of the comments field, preceeded by Comments:


Kind regards,
Stephan Linke, Tech Support Team

Created on Feb 3, 2018 11:30:17 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Stephan,

The code you provided didn't worked.

my Placeholders, from EXE:

`$Placeholders = @("sensorPARENTGROUP", "deviceURL", "sensorPARENTDEVICE", "sensorURL", "sensorNAME", "sensorSTATUSTEXT", "%datetime")`

my HTML snippet: `padding: 10px; border: 1px solid #ddd8d6;color:#00264d;"> {6}</td>`

All the placeholders worked, but the "%datetime".

May you help me?

Created on Aug 17, 2018 3:00:54 PM by  Jesus (10) 1



Votes:

0

Your Vote:

Up

Down

Could you post your entire template, please?


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 20, 2018 5:40:08 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Stephan,

Figured out how this part worked. I was trying to use the % placeholder type direct from the command line, and now I know it won't work, but does if I pass the parameters from PRTG notification, cool.

But now another problem: The notification as a whole ain't work if it's called from PRTG, but will if I do directly from command line, with the exactly same parameters. Any idea on what could lead to this?

Let me know if you need more info, but, the code as a whole is kind of the same up there (GitHub link), but filled with our credentials and with some $global:foobar removed.

Created on Aug 20, 2018 3:10:20 PM by  Jesus (10) 1



Votes:

0

Your Vote:

Up

Down

Do you see any errors under Logs | System Related | Notifications? Did you configure the Execution-Policy according to this article?


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 20, 2018 6:31:05 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

After some good hours trying to figure it out, I did. Turned out the problem wasn't the script, nor PRTG, nor the script call by PRTG. The problem was the timeout setted by default in a custom exe notification, which is 5 seconds. Changed it to 60 seconds and it's working well now. Thanks for you assist, and, maybe, tell the devs to change the default timeout to something higher, maybe other people would get stuck in such thing too.

Regards, Jesus.

Created on Aug 20, 2018 7:08:57 PM by  Jesus (10) 1



Votes:

0

Your Vote:

Up

Down

I have now a simple problem. Since I can't use the %placeholder format within the script, I need to pass they as parameters in the PRTG call to the script. But, I need to place the placeholders as comma separated, but PRTG will put a ` before every comma, what makes the code fail to execute. Any ideas on how to make it work? my actual parameters line is: -SensorID %sensorid -Placeholders '%group','deviceURL','%device','sensorURL','%sensor','%message','%lastup'

Created on Aug 20, 2018 7:56:51 PM by  Jesus (10) 1



Votes:

0

Your Vote:

Up

Down

It should be -Placeholders @('%group','deviceURL','%device','sensorURL','%sensor','%message','%lastup')... but the parameter pass of special characters (@ and ( ) ) is currently broken :( I'm sorry that this is a somewhat tedious process currently :( The easiest would be to configure all placeholders directly in the script (in the parameters) and use them accordingly in the templates with their corresponding counters ({0}, {1}, etc.).


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 20, 2018 8:07:17 PM by  Stephan Linke [Paessler Support]

Last change on Aug 20, 2018 8:08:08 PM by  Stephan Linke [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Well, thats actually pretty sad, since the %placeholder style would work only if called as parameter from PRTG, not from the script, and it would inutilize most of the PRTG's placeholders. So, after some work, I made it work too.

In the script, comment the $Placeholders = @() line inside Params. Create a new line with $Placeholder = "", in it. It will create a String, instead of an Array, as the old variable. A little below, since the whole script is made to work with the placeholders as array, we need to convert the variable we just created to an array type. To do this we need the split method. Do it as follows:

[System.Array]$Placeholders = $($Placeholder -split ",,"); Important here is that the String one is Placeholder, in singular, meanwhile the array created above is in plural, as in the original code, so you don't need to change anything else.

Enough edit in the code, now the PRTG Parameters line in the custom exe notification should look something similar to this (but with your placeholders instead):

-SensorID %sensorid -Placeholder "%group,,deviceURL,,%device,,sensorURL,,%sensor,,%message,,%datetime"

The %sensorid will pass to the script the actual sensor, so it will work properly. Without this automation, the script has no sense at all.

I chose the double comma (,,) because I think it's something pretty hard to appear legimate in any part of the PRTG answer, or in any device name or anything else, but you could have chose anything, just remember to change it in the Split method in the code. After it your automatic notification with powershell should be working as expected.


Best regards,

Jesus.

Created on Aug 21, 2018 11:39:01 AM by  Jesus (10) 1



Votes:

0

Your Vote:

Up

Down

Thanks for the interim "patch" and sharing of the same! :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 21, 2018 11:50:37 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Why use such a complex system for custom email templates? Why not having something GUI based, which would be much more user friendly, like the map builder?

Almost everything custom within PRTG feels like a chore, rather than something you should be able to "just do"..

Created on Jun 7, 2019 9:10:07 AM by  ACoates (0) 1



Votes:

0

Your Vote:

Up

Down

We had it built-in, the code for it was very, very cumbersome, near impossible to maintain. Storing the HTML within the configuration, parsing it for malicious code, escaping control characters so they won't interfere with the configuration was a nightmare. That's why we decided to remove it.

We figured that we should give customers an opportunity to still send customized mails. I agree, it's comlplex to set up, but we don't have an alternative, unfortunately.

Created on Jun 11, 2019 6:16:46 AM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.