?
Solved

Email From Powershell

Posted on 2014-01-16
5
Medium Priority
?
409 Views
Last Modified: 2014-01-21
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!
0
Comment
Question by:Sedgwick_County
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 39787039
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 mail.here.com -From me@here.com -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.
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39787068
Function Mailer ($emailTo)
{
   $message = @"
                                 
Some stuff that is meaningful  
 
Thank you,
IT Department
Cotendo Corporation
it@cotendo.com
"@        
 
$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)
}
$i=0
$Addresses=get-content c:\contacts.txt
Foreach($address in $Addresses)
{

Mailer($address)
if($i%15 -eq 0)
{
  Start-sleep -m 10
}
  $i=$i+1
}
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39787080
$i%15 will build blocks of 15 mails (instead of 30), and Start-sleep -m 10 only waits 10 millisec ...
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39787087
Oops, thought 15 in bunch
Thanks.
0
 

Author Closing Comment

by:Sedgwick_County
ID: 39797528
That worked perfectly!  Thank you VERY much on your fast response.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question