Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Email From Powershell

Posted on 2014-01-16
5
Medium Priority
?
412 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 71

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 71

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

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

609 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