Benachrichtigungen
Alles löschen
Exchange Server 2019
2
Beiträge
2
Benutzer
0
Reactions
1,386
Ansichten
Themenstarter 3. Juni 2022 11:04
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
}
3. Juni 2022 14:07
To sleep a PowerShell script for 10 seconds, you can run the following command
Start-Sleep -Seconds 10