I’m doing some load testing on one of my SMTP Smart Hosts, and needed to send a few thousand emails in a controlled space of time. I’ve written this quick little script to do so:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
|
$scriptSettings = @{ NumberOfEmails = 100 TimeBetweenEmails = 1 #in seconds MailDestination = 'kim.akers@contoso.com' MailSubject = 'Test' MailServer = 'mail.contoso.com' MailFrom = 'no-reply@contoso.com' } for ( $i =1; $i -le $scriptSettings .NumberOfEmails; $i ++) { try { Send-MailMessage ` -To $scriptSettings .mailDestination ` -Subject $scriptSettings .mailSubject ` -SmtpServer $scriptSettings .mailServer ` -From $scriptSettings .From ` -Body "Email number $i" } catch { "Error sending email $i" } Start-Sleep -Seconds $scriptSettings .TimeBetweenEmails } |