Send Emails Easily Using Powershell v2 Cmdlet Send-MailMessage…
Most exchange admins would have written atleast a single script, maybe a very simple one. One of the most common scripts used in messaging environments is to email the exchange admin the total number of mailboxes in the organization (on a weekly basis for example) or to email the list of large mailboxes. You can…
Most exchange admins would have written atleast a single script, maybe a very simple one. One of the most common scripts used in messaging environments is to email the exchange admin the total number of mailboxes in the organization (on a weekly basis for example) or to email the list of large mailboxes. You can run powershell scripts to automate a number of processes and have that emailed to you.
Getting powershell to send an email was not straightforward in Exchange 2007, with powershell v1. We had to make use of the System.Net.Mail class and there are number of articles explaining the process.
With the release of Powershell v2, things get much easier. It has a new cmdlet for sending emails, “Send-MailMessage”. More info here
This cmdlet works in both Exchange 2007 SP2+ & 2010. Yes, I said 2007 SP2, provided that you have Powershell v2 installed. Check my previous article to know more about powershell v2 support for exchange 2007 SP2 here.
It is highly unlikely that you will have PS v2, unless you are creating a new environment from scratch. Exchange 2010 needs PS v2 by default and hence the cmdlet will run fine.
Let me explain with an example. I am running Exchange 2007 SP2 on Windows 2008 SP2 with Powershell v2 installed. I want to send an email from my account to my colleague Deepak with subject as “Test Email” and body as “Testing the cmdlet”. I ran the following in exchange shell.
Send-MailMessage –From Rajith@chakka.local –To Deepak@chakka.local –Subject “Test Email” –Body “Testing the cmdlet” –SmtpServer exch07.chakka.local
The send-mailmessage cmdlet will work straight from a Powershell v2 console as well.
I checked Deepak’s OWA and there it is, the email that I had sent with the above syntax.
Scripts get shorter with Powershell v2!
Thank you very much, it helped a lot
Glad the article helped you Shreyas.
Very helpful, thanks!
Glad to help Chris.
Thanks Raj, I used this today!
See you Monday :)