Laeeq Qazi's Exchange Server Blog

Exchange Server blog

Send Email via PowerShell cmdlet Send-MailMessage

## Start of Scirpt ##

##This script reads Recipinets and Email Contents from 2 different text files
##And then sends email to all of the recipients

$cred =Get-Credential;
$smtpServer = “”

$Mailboxes = Get-Content c:\mailboxes.txt
$Email = Get-Content c:\Email.txt

$Contents = “”;
$Sender = “”;

foreach($row in $Email){$Contents+= $row};

foreach($mailbox in $Mailboxes)
$mailbox = $mailbox.Trim();
$sub = “Hi $mailbox “;
$From = $Sender;

$To= $mailbox;
$body= $Contents;

if($To -ne $null -and $To -ne ”)
send-mailmessage -from $From -to $To -subject $sub -credential $cred -body $body -smtpServer $smtpServer

## End of Scirpt ##

This script uses powerShell 2.0 command send-mailmessage to send the mail message to various recipients, who are placed in a text file , each recipient on a single line like this: etc.

Script reads the Email contents from text file too, which makes this script dynamic. I used this script while working a email extracting application for load testing.  I had to work on very heavy mailboxes, with 10,000+ emails, and I used this script with one other loop, to send 2000 emails via single command.

I hope it help you.


Laeeq Qazi

December 7, 2011 Posted by | Uncategorized | 2 Comments

2010 in review

The stats helper monkeys at mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads This blog is doing awesome!.

Crunchy numbers

Featured image

A helper monkey made this abstract painting, inspired by your stats.

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 3,600 times in 2010. That’s about 9 full 747s.


In 2010, there were 6 new posts, growing the total archive of this blog to 7 posts.

The busiest day of the year was November 4th with 41 views. The most popular post that day was Manually Generating Offline Address Book on Exchange 2007/2010.


Where did they come from?

The top referring sites in 2010 were,,,, and

Some visitors came searching, mostly for msexchquerybasedn exchange 2010, exchange 2010 change gal for users, laeeq qazi, powershell display msexchquerybasedn, and moveallreplicas.ps1 exchange 2010.

Attractions in 2010

These are the posts and pages that got the most views in 2010.


Manually Generating Offline Address Book on Exchange 2007/2010 February 2010


How to set GAL for mailboxes in OWA for Exchange 2007/2010 in bulk April 2010
4 comments and 1 Like on,


How to uninstall Exchange Server 2007 May 2010


About Laeeq Qazi November 2008


How to remove client permissions from a public folder and all its children? June 2010

January 2, 2011 Posted by | Uncategorized | Leave a comment