Solved

Powershell script to parse through sender list and send out message

Posted on 2010-08-26
2
910 Views
Last Modified: 2012-06-27
Hello everyone,

I need help with a powershell script that will do the following:

1-parse through a csv file and create a list of emails and first name (and maybe place them in two separate arrays)
2- get content of a text file and use as a body of an email message
3- send out emails (at once or one-by-one) to the email addresses and first names parsed from step one.

not really sure how could this be accomplished, but I was thinking something among the following lines (total pseudo code :))

$PathToFiles= c:\testpath
$E-mailSubject= "My Dissertation"

(Now, here's where is gets interesting and confusing)

$ListofFirstNames=  import-csv $PathToFiles\ListofNamesAndEmailAddress.csv |select First_Name
$firstname= for each-item in $ListofFirstNames

$ListofEmails= import-csv $PathToFiles\ListofNamesAndEmailAddress.csv |select E-mail
$mailto= for each-item in $ListofEmails

the emailbody.doc will look something like this:
"Dear $firstname,
bla bla bla bla
Thank you"

$E-MailBody= Get-Content "$PathToFiles\e-mailbody.doc" (replacing each $firstname with a name from the first name arrary)
$sendto= $mailto (one email address per message)
$send-message

I know this isn't very clear, so please feel free to ask any questions you may have.  I'm using powershell 2.0 ctp3

thanks in advance
0
Comment
Question by:bloodywicked
[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 Comments
 
LVL 32

Accepted Solution

by:
endital1097 earned 500 total points
ID: 33535478
i think we just need to work on the body
the columns i'm using in the csv are email and firstname
$SmtpClient = New-Object system.Net.Mail.SmtpClient
$MailMessage = New-Object system.Net.Mail.MailMessage
$SmtpClient.Host = "exch.contoso.com"
$MailMessage.From = "Somone <sender@contoso.com>"
$MailMessage.Subject = "Powershell message"
$MailMessage.IsBodyHtml = $True

$body = @()
import-csv c:\messages.csv | foreach-object { $MailMessage.To.Add($_.email);
$body = "Dear $_.FirstName
$body += Get-Content "C:\yourtext.txt"
$MailMessage.Body = $body
$smtpClient.Send($MailMessage)
}

Open in new window

0
 
LVL 32

Expert Comment

by:endital1097
ID: 33535618
one change where ` is the character next to the 1, not the apostrophe
$body = "Dear " + $_.FirstName + "`n"

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

630 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