Send Bulk Test Emails with PowerShell
Written on August 11, 2011

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:

$scriptSettings = @{
  NumberOfEmails = 100
  TimeBetweenEmails = 1 #in seconds
  MailDestination = '[email protected]'
  MailSubject = 'Test'
  MailServer = 'mail.contoso.com'
  MailFrom = '[email protected]'
}
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
}

Comments/questions

There's no commenting functionality here. If you'd like to comment, please either mention me (@[email protected]) on Mastodon or email me. I don't have any logging or analytics running on this website, so if you found something useful or interesting it would mean a lot to hear from you.