Send email to list of email id's in an csv file

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 1 year, 8 months ago.

  • Author
    Posts
  • #29348
    Profile photo of nidhinck
    nidhinck
    Participant

    Hi Experts,

    I have an csv file which contains a field named "Primary Owner" and it contains email id's of users. I would like to send email to those users in single email using powershell. How can i do that.

    PrimaryOwner
    ———————–
    abc@yammer.com
    cdf@yammer.com

    Normally i will define the users in To section like below.. but here, the ccsv file content will change in each time

    $to = "abc@yammer.com","cdf@yammer.com"

    Send-MailMessage -SmtpServer server1 -To $to -From $from -Subject $subject -Body $body -BodyAsHtml

  • #29352
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    You would need to use Import-CSV to read in your CSV file and then loop through the records using a ForEach-Object something like:


    Import-CSV inputfile.csv | ForEach-Object {Send-MailMessage -SmtpServer server1 -To $_.PrimaryOwner -From $from -Subject $subject -Body $body -BodyAsHtml}

You must be logged in to reply to this topic.