What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Multiple headers for different e-mail notifications

Votes:

0

Hello,

Today i encountered a problem about the notification to e-mail option in PRTG. We are currently using a service desk program that has a mail-import function. What we are trying to achieve that PRTG sends a notification by mail and that the service desk program automatically takes over the e-mail to escalate it to our service desk software. This is working all fine, but the problem is that i have to use multiple mail imports and the program uses it's information from the e-mail header of the PRTG notification e-mail.

Is it possible to change the e-mail header for every notification send by e-mail? The only setting i found was the main e-mail header which applies on every notification e-mail send by PRTG.

e-mail header notifications

Created on Apr 3, 2014 3:13:01 PM



Best Answer

Accepted Answer

Votes:

0

You could create a custom notification to execute this PowerShell script to send notifications with custom header data (see Line 53). Alternatively you could look into the PRTG ticket system.

##############################################################################
##
## Send-MailMessage
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
## Illustrate the techniques used to send an email in PowerShell.
## In version two, use the Send-MailMessage cmdlet.
##
## Example:
##
## PS >$body = @"
## >> Hi from another satisfied customer of The PowerShell Cookbook!
## >> "@
## >>
## PS >$to = "[email protected]"
## PS >$subject = "Thanks for all of the scripts."
## PS >$mailHost = "mail.leeholmes.com"
## PS >Send-MailMessage $to $subject $body $mailHost
##
##############################################################################
 
param(
    ## The recipient of the mail message
    [string[]] $To = $(throw "Please specify the destination mail address"),
 
    ## The subjecty of the message
    [string] $Subject = "<No Subject>",
 
    ## The body of the message
    [string] $Body = $(throw "Please specify the message content"),
 
    ## The SMTP host that will transmit the message
    [string] $SmtpHost = $(throw "Please specify a mail server."),
 
    ## The sender of the message
    [string] $From = "$($env:UserName)@example.com"
)
 
## Create the mail message
$email = New-Object System.Net.Mail.MailMessage
 
## Populate its fields
foreach($mailTo in $to)
{
    $email.To.Add($mailTo)
}
 
$email.From = $from
$email.Subject = $subject
$email.Body = [string]::Format("{0}",$body);
$email.Headers.Add("X-Company", "My Company");
 
## Send the mail
$client = New-Object System.Net.Mail.SmtpClient $smtpHost
$client.UseDefaultCredentials = $true
$client.Send($email)

The script has to be called with the following parameters:

.\mail.ps1 [email protected] "My Subject" "Hello World" my.mailserver.com [email protected]

Created on Apr 7, 2014 12:22:09 PM by  Stephan Linke [Paessler Support]

Last change on Apr 13, 2016 10:29:34 AM by  Stephan Linke [Paessler Support]



5 Replies

Votes:

0

Unfortunately it's not possible to set mail header options specifically for single notifications. Is it possible for your service desk program to filter by other criteria, i.e. mail subject?

Created on Apr 4, 2014 3:25:57 PM by  Stephan Linke [Paessler Support]



Votes:

0

First of all thanks for your reply,

Yes this is possible but the most important criteria is the company name which takes it's information from the header/sender information that is send by PRTG.

We just wanted to know if it's possible to change this data but according to you it's unfortunately not possible. It's a answer to my question but i'm afraid that there is no solution.

Created on Apr 7, 2014 10:47:54 AM



Accepted Answer

Votes:

0

You could create a custom notification to execute this PowerShell script to send notifications with custom header data (see Line 53). Alternatively you could look into the PRTG ticket system.

##############################################################################
##
## Send-MailMessage
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
## Illustrate the techniques used to send an email in PowerShell.
## In version two, use the Send-MailMessage cmdlet.
##
## Example:
##
## PS >$body = @"
## >> Hi from another satisfied customer of The PowerShell Cookbook!
## >> "@
## >>
## PS >$to = "[email protected]"
## PS >$subject = "Thanks for all of the scripts."
## PS >$mailHost = "mail.leeholmes.com"
## PS >Send-MailMessage $to $subject $body $mailHost
##
##############################################################################
 
param(
    ## The recipient of the mail message
    [string[]] $To = $(throw "Please specify the destination mail address"),
 
    ## The subjecty of the message
    [string] $Subject = "<No Subject>",
 
    ## The body of the message
    [string] $Body = $(throw "Please specify the message content"),
 
    ## The SMTP host that will transmit the message
    [string] $SmtpHost = $(throw "Please specify a mail server."),
 
    ## The sender of the message
    [string] $From = "$($env:UserName)@example.com"
)
 
## Create the mail message
$email = New-Object System.Net.Mail.MailMessage
 
## Populate its fields
foreach($mailTo in $to)
{
    $email.To.Add($mailTo)
}
 
$email.From = $from
$email.Subject = $subject
$email.Body = [string]::Format("{0}",$body);
$email.Headers.Add("X-Company", "My Company");
 
## Send the mail
$client = New-Object System.Net.Mail.SmtpClient $smtpHost
$client.UseDefaultCredentials = $true
$client.Send($email)

The script has to be called with the following parameters:

.\mail.ps1 [email protected] "My Subject" "Hello World" my.mailserver.com [email protected]

Created on Apr 7, 2014 12:22:09 PM by  Stephan Linke [Paessler Support]

Last change on Apr 13, 2016 10:29:34 AM by  Stephan Linke [Paessler Support]



Votes:

0

Thanks for your reply, really helpful. I will try this asap.

Created on Apr 7, 2014 2:57:05 PM



Votes:

0

Can you try the updated script? I modified the following line:

$email.Body = [string]::Format({0},$body);

...just to make sure that the double colon is escaped correctly.

Created on Feb 8, 2016 9:44:46 AM by  Stephan Linke [Paessler Support]




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.