Powershell: Sending...
 
Notifications
Clear all

Powershell: Sending bulk e-mails

2 Posts
2 Users
0 Reactions
1,423 Views
(@Anonymous)
New Member
Joined: 1 second ago
Posts: 0
Topic starter  
 

I would like to send bulk e-mail via powershell from exchange server. I found this script on the net which is what I was looking for. However, to avoid spam blocking, I would like to send a few thousand emails in a controlled space of time.

How can I add a line for Time Between Emails? I would like the script to send one e-mail every 10 second.

Can you help? Thanks

$thisScript = $myInvocation.MyCommand.Path
$scriptRoot = Split-Path(Resolve-Path $thisScript)
$recipientsListFile = Join-Path $scriptRoot "recipientsList.txt"
$EmailBodyFile = Join-Path $scriptRoot "EmailBody.txt"

$arrEmailBody =@()
$arrEmailBody += Get-Content $EmailBodyFile
$strsmtp = "<SMTP Server>"
$strSubject = "<Email Subject>"
$fromEmail = "<Sender's Email>"
$fromName = "<Sender's Name>"
$Sender = New-Object System.Net.Mail.MailAddress($fromEmail, $fromName)

$port = 25

$SMTPClient = New-Object System.Net.Mail.smtpClient
$SMTPClient.host = $strsmtp
$SMTPClient.port = $port


foreach ($item in (Get-Content $recipientsListFile))
{
    $MailMessage = New-Object System.Net.Mail.MailMessage
    $strName = ($item.split(";"))[0]
    $strEmail = ($item.split(";"))[1]

$strBody = @"
Dear $strName


"@
Foreach ($line in $arrEmailBody)
{
$strBody = $strBody + @"
$line

"@
}

    $objRecipient = New-Object System.Net.Mail.MailAddress($strEmail, $strName)
    $MailMessage.Subject = $strSubject
    $MailMessage.Sender = $Sender
    $MailMessage.From = $Sender
    $MailMessage.To.add($objRecipient)
    $MailMessage.Body = $strBody
    $SMTPClient.Send($MailMessage)
    Remove-Variable objRecipient
    Remove-Variable mailMessage
}

   
Quote
(@exsus)
Trusted Member
Joined: 4 years ago
Posts: 83
 

To sleep a PowerShell script for 10 seconds, you can run the following command

Start-Sleep -Seconds 10

   
ReplyQuote

Share: