Scheduled Task

How to send email alerts via Task Scheduler in Server 2012 R2

Posted on Updated on

In Server 2008 R2 task scheduler, the send email feature is available as an option.  And I have used this feature a lot mostly for my phone system servers because I get real time alerts whenever there is a potential issues on switches and servers.

When 2012R2 came out, the send mail feature was not longer available.

I am making this post to help others out there with the same issues and hopefully you will find this post useful to you.

Here are the procedures:

1.  Create a powershell script to send emails, the entries for Attachment, SMTPPort, and UseSSL are optional unless required.

##############################################################################

$From = “alert@email.com”

$To = “user@email.com”

$Cc = “boss@email.com”

$Attachment = “C:\temp\Some random file.txt”

$Subject = “Subject here”

$Body = “Body of the email here”

$SMTPServer = “smtprelay.your.org”

$SMTPPort = “52”

Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer#-port $SMTPPort -UseSsl #-Credential (Get-Credential) # -Attachments $Attachment

##############################################################################

2.  Next is to create your scheduled task, and under Actions, add the powershell script to send the email.

 

taskscheduler

 

This is very simple yet very useful to anyone that wants to setup a scheduled task that also sends email alerts.  Although you can have SCOM send those alerts, it is still useful if you can do it directly from the server.

Please do not forget to leave me a comment if you see any corrections, or if you have any suggestions.  Or better, if you like this post, please feel free to let me know.  It won’t cost you anything.