# Script      : SMTP-SENT-BULK-EMAILS.ps1  
# Created     : ISE 3.0   
# Author(s)   : Casey.Dedeal   
# Date        : 10/11/2019 14:46:37   
# Org         : ETC Solutions  
# File Name   : SMTP-SENT-BULK-EMAILS.ps1  
# Comments    : Relay Test Bulk Emails 
# Assumptions :  
DESCRIPTION        : Sent Bulk SMTP Mails  
Acknowledgements   : Open license  
Limitations        : None 
Known issues       : None  
Credits            : None  
  #(1)_.Mail Gateways  
  #(2)_.Adjust Subject & BODY & From addess Vars 
  #(3)_.Define Folder Location 
  #(4}_.Define Att Names 
  #(5)_.Create folder 
  #(6)_.Verify Attachment List  
  #(7)_.Constract SMTP ARRAY List 
  #(8)_.Add Counter 
  #(9)_.Provide Info 
  #(10)_.Starting loop  
  #(11)_.Loop for Sending email 
  #(12)_.Sending Message 
#(1)_.Define SMTP Relay Host  
$smtpserver1    = "MailRelay1.Your_relay.com"  
$smtpserver2    = "MailRelay2.Your_relay.com" 
#(2)_.Adjust Subject & BODY & From addess Vars 
$Subject      = "Bulk Mail Relay test"  
$body         = "Sending BULK EMAILS to Multiple recepients"  
$fromaddress  = "SpamKing@SpamKingdom.com" 
#(3)_.Define Attachment List 
$attname1 = "This_File_is_ALLOWED.zip" 
$attname2 = "This_File_is_FORBIDEN.zip" 
#(4)_.Define Folder Location 
$user = $env:USERNAME 
$AttPath  = "C:\Users\$user\Desktop\Reports_\Relay_Test\" 
#(5)_.Define Attc Names 
$att1  = $AttPath + $attname1 
$att2  = $AttPath + $attname2 
#(6)_.Create folder 
If (!(Test-Path $AttPath)) { 
New-Item -ItemType Directory -Force $AttPath | Out-Null 
#(7)_.Verify Attachment List  
If (!(Test-Path $att1) ){ 
  Write-host "Attachment NOT found" -f Red 
  Write-Warning "[$att1] FAILED" 
  Write-Warning "Script wll stop" 
  Start-Sleep -Seconds 5 
If (!(Test-Path $att2) ){ 
  Write-host "Attachment NOT found" -f Red 
  Write-Warning "[$att2] FAILED" 
  Write-Warning "Script wll stop" 
  Start-Sleep -Seconds 5 
#(8)_.Constract SMTP ARRAY List 
 # On Prem  
#(9)_.Add Counter 
$i = 1 
#(10)_.Provide Info 
$HowMany =  Read-host "(-)_.Provide <Number> for bulk emails" 
Write-host "[$HowMany] Emails will be sent out" -f Cyan 
Write-warning "Recepients List"  
Write-host "---------------------------------------" - -f Yellow -b black 
Write-host "---------------------------------------" -f Yellow -b black 
Read-Host "press <ENTER> to continue" 
#(11)_.Starting loop  
foreach($RelayTest in 1..$HowMany){ 
Write-Progress -activity "Processing " -status "$i" 
#(12)_.Loop for Seding email 
foreach ($toaddress in $array) 
Write-Progress -activity "Processing " -status "$i" 
Write-host "Sending mail to ($toaddress)" -f Cyan 
#(13)_.Sending Message 
$message = new-object System.Net.Mail.MailMessage  
$message.From = $fromaddress  
$message.To.Add($toaddress$message.IsBodyHtml = $True  
$message.Subject = $Subject  
$attach = new-object Net.Mail.Attachment($att3)  
$message.body = $body  
$smtp = new-object Net.Mail.SmtpClient($smtpserver2)  
Write-host "Done" -f yellow 

Attached Powershell will assist sending Bulk SMTP mail to your test server. SMTP relay server, subject line, body information, attachment , can easily be changed to fix into your own requirenments. Script will require to change certain variables based on your environment. Script has been tested and verified. Give it a try and let me know what do you think.



1_.Mail Gateways

2_.Adjust Subject Body and From Addresses

3_.Define Folder Location

4_.Define Att names

5_.Create Folder

6_.Verify Attachment List

7_.Add Counter

8_.Provide Info

9_.Start loop

10_.Loop for sending mail

11_.Sending message