{"id":2355,"date":"2017-08-29T21:43:42","date_gmt":"2017-08-29T21:43:42","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2355"},"modified":"2023-05-12T13:22:48","modified_gmt":"2023-05-12T18:22:48","slug":"send-bulk-test-emails-with-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2355","title":{"rendered":"Send Bulk Test Emails with PowerShell"},"content":{"rendered":"<p>I&#8217;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\u2019ve written this quick little script to do so:<\/p>\n<div>\n<div id=\"highlighter_432007\" class=\"syntaxhighlighter  powershell\">\n<p><span style=\"color: #0000ff;\">$scriptSettings = @{<\/span><br \/>\n<span style=\"color: #0000ff;\">NumberOfEmails = 100<\/span><br \/>\n<span style=\"color: #0000ff;\">TimeBetweenEmails = 1 #in seconds<\/span><br \/>\n<span style=\"color: #0000ff;\">MailDestination = &#8216;user.name@contoso.com&#8217;<\/span><br \/>\n<span style=\"color: #0000ff;\">MailSubject = &#8216;Test&#8217;<\/span><br \/>\n<span style=\"color: #0000ff;\">MailServer = &#8216;mail.contoso.com&#8217;<\/span><br \/>\n<span style=\"color: #0000ff;\">MailFrom = &#8216;no-reply@contoso.com&#8217;<\/span><\/p>\n<p><span style=\"color: #0000ff;\">}<\/span><\/p>\n<p><span style=\"color: #0000ff;\">for ($i=1; $i -le $scriptSettings.NumberOfEmails; $i++) {<\/span><br \/>\n<span style=\"color: #0000ff;\">try { Send-MailMessage `<\/span><br \/>\n<span style=\"color: #0000ff;\">-To $scriptSettings.mailDestination `<\/span><br \/>\n<span style=\"color: #0000ff;\">-Subject $scriptSettings.mailSubject `<\/span><br \/>\n<span style=\"color: #0000ff;\">-SmtpServer $scriptSettings.mailServer `<\/span><br \/>\n<span style=\"color: #0000ff;\">-From $scriptSettings.From `<\/span><br \/>\n<span style=\"color: #0000ff;\">-Body &#8220;Email number $i&#8221;<\/span><\/p>\n<p><span style=\"color: #0000ff;\">} catch { &#8220;Error sending email $i&#8221; }<\/span><\/p>\n<p><span style=\"color: #0000ff;\">Start-Sleep -Seconds $scriptSettings.TimeBetweenEmails<\/span><br \/>\n<span style=\"color: #0000ff;\">}<\/span><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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\u2019ve written this quick little script to do so: $scriptSettings = @{ NumberOfEmails = 100 TimeBetweenEmails = 1 #in seconds MailDestination = &#8216;user.name@contoso.com&#8217; MailSubject = &#8216;Test&#8217; MailServer = &#8216;mail.contoso.com&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,59],"tags":[],"class_list":["post-2355","post","type-post","status-publish","format-standard","hentry","category-ad","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2355"}],"version-history":[{"count":3,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2355\/revisions"}],"predecessor-version":[{"id":3353,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2355\/revisions\/3353"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}