Wednesday, September 10, 2014

#26 : How to send SMTP Mail with Powershell ?

Many of your scripts require to send mail. There are several ways to send mail, but I am introducing you with SMTP mail sending script here. The code will accept below values which either you can hard-code inside the script or you can make a config file or ini file to get the settings. Below is simple piece of code for the same:



How to send mail to multiple recipients?

This can be done by modifying NOTIFY_ID variable with below -

$NOTIFY_ID=som@foo.com,john@foo.com


Make sure you are using a comma(,) to separate two Mail-Ids.

How to Send HTML Formatted mail using Powershell ?

This is another good option which can be done easily with Powershell. You need to just add one more line inside the code:



Easy and Simple. Enjoy Scripting!!

4 comments:

  1. I have updated the article with attachment option.

    ReplyDelete
  2. The message indicates that the message you supplied to the smtp server is not accepted for some reason, but doesn't really say what piece went wrong. You could try this article:

    http://www.powershellcave.com/?p=46

    It was really helpfull for me when I tried understanding the powershell email functions.

    ReplyDelete
  3. So, here is a question. I used the above script but I keep on getting double messages. Why would that happen?

    ReplyDelete
  4. By double messages, I mean I get double emails from the script.

    ReplyDelete

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...