Email From Powershell

I am trying to find a good code where I can send email through a Powershell Script.  

Here is the situation:  
We have 6,550 contacts we need to verify to make sure they are still valid or not.  We want to shot them an email but not kill our reputation online against the Spam filters.

What we need:
Is a powerhsell scrip that can read from a text document that has email addresses and grab 30 at a time every 10-15 seconds and send an email to them.  We need to be able to specify who its from (will always be the same account) and it will always have the same message in the body.

Any help would be greatly appreciated!
Who is Participating?
QlemoConnect With a Mentor Batchelor and DeveloperCommented:
Roughly that should do that:
$Body = @"
The email body text,
in several lines.
Could also be a text or html file

$cnt = 0
foreach ($to in get-content C:\EMailAddress.txt)
  Send-MailMessage -SmtpServer -From -To $to -Subject 'TestMail' -Body $body
  if ((++$cnt % 30) -eq 0)
    Write-Host 'Waiting for 15 seconds ...'
    Start-Sleep 15 

Open in new window

This can be expanded by adding the -BodyAsHtml to Send-MailMessage if your mail body consists of HTML code.
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Function Mailer ($emailTo)
   $message = @"
Some stuff that is meaningful  
Thank you,
IT Department
Cotendo Corporation
$emailFrom = "noreply@<yourdomain>.com"
$subject="<Your Text Here>"
$smtpserver="<your mailhost>.<yourdomain>.com"
$smtp=new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $message)
$Addresses=get-content c:\contacts.txt
Foreach($address in $Addresses)

if($i%15 -eq 0)
  Start-sleep -m 10
QlemoBatchelor and DeveloperCommented:
$i%15 will build blocks of 15 mails (instead of 30), and Start-sleep -m 10 only waits 10 millisec ...
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Oops, thought 15 in bunch
Sedgwick_CountyAuthor Commented:
That worked perfectly!  Thank you VERY much on your fast response.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.