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.

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

My IMAP sensor does not process HTML emails correctly using regex. What can I do?



Your Vote:



We monitor several backup services which send emails about their status just like described in this article. In order to get an error status as soon as a backup failed, we use regular expressions in the search text field. If the email body does not contain “Failed Backups: 0” (but a number bigger than 0), for example, we want to set the sensor to alarm.

For plain text emails, this works as expected. However, some solutions send HTML emails. The IMAP sensor obviously recognizes these emails but switches into an error status erroneously even if the regex in the search text field does match the "successful backup" condition.

The sensor log shows that the sensor seems to analyze only a part of HTML emails. Is there any solution to this issue?

backup-monitoring email email-sensor imap imap-sensor prtg regex regular-expression

Created on Jul 25, 2014 1:47:45 PM by  Gerald Schoch [Paessler Support]

1 Reply

Accepted Answer



Your Vote:



This article applies to PRTG Network Monitor 13 or later

IMAP Sensors with RegEx for HTML Emails

If you encounter issues regarding the correct matching of regular expressions, please first check the correct definition of your regex with a test tool (for example, Then check which type of emails the IMAP sensor has to analyze. If the emails contain an HTML body, then ensure that your regular expression also matches additional source code!

Analyze the HTML Content of the Email

In some cases, the email server (e.g., Microsoft Exchange) creates additional HTML markups within the source code of an email, for example, line breaks or paragraph breaks. So please check what exactly the HTML code contains after the email has been delivered. You can view the HTML code of an email if you save it as .html and open it with an editor (in Outlook: File | Save as).

Depending on the additional HTML code in the email, adjust the regular expression of your IMAP sensor! Ensure that the regex also matches line breaks, paragraphs, tables, etc. The example below will give you an idea of what you have to consider.


Consider the example in the question part of this article. Let’s assume that our IMAP sensor should show an alert if the target email does not contain the expression Failed Backups: 0 because in this case there would be at least one failed backup.

Then you might have the idea to define the following regular expression in the search text field of the sensor settings: Failed Backups: [^\d]*0[^\d]

For plain text emails, this regex would work perfectly. If there is another number than 0, the sensor would switch into an error status. However, the defined regular expression assumes that there is no other character between “Failed Backups:” and “0”. But if your service sends HTML encoded emails, there might be some HTML tags in between. This could look like the following example: <tr style='mso-yfti-irow:4'> <td width=350 valign=top style='width:262.5pt;padding:1.5pt 1.5pt 1.5pt 1.5pt'> <p class=MsoNormal>Failed Backups:</p> </td> <td valign=top style='padding:1.5pt 1.5pt 1.5pt 1.5pt'> <p class=MsoNormal>0</p> </td> </tr>

So, after analyzing the actual content of the HTML encoded email body, you might have the idea to use a dot "." in your regex which should match all characters: Last Failed Backups.*0

But this would not work either because the dot does not match line breaks which the HTML code most likely contains.

Solution: Use the dot matches all regex option: You can switch it on with (?s) and off with (?-s). Furthermore, add the left angle bracket < of the HTML tag which follows “0” to your regex in octal notation in order to close the search space: \074

The resulting regular expression to match Failed Backups: 0 then is: Failed Backups:(?s).*0(?-s)\074

Analyze your HTML encoded emails and adjust your defined regular expression in a similar way if your IMAP sensor does not recognize them correctly. Always think of potentially appearing additional HTML markups!

Created on Jul 25, 2014 1:54:17 PM by  Gerald Schoch [Paessler Support]

Last change on Oct 9, 2015 11:21:36 AM by  Luciano Lingnau [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.