Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Change script to look at text file for destination email addresses

I would like to change this script, so that instead of hard coding in the destination email addresses, it will look into a flat txt file and use the email addresses listed in that specific file instead.


###SETUP START###
#-------DO NOT MODIFY-------#
    #Yesterdays Date
        $date = ((Get-Date).AddDays(-2)).ToString("MMM/dd/yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" REVISED "
    #Body of Email
        $MessageBody = "REVISED - Report for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'email1@mail.com' -To 'email2@mail.com', 'email3@mail.com', 'email4@mail.com' `
  -SmtpServer 'smtp.mail.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\Attachment.pdf'
 ###PROGRAM END###

Thanks in advance for your assistance
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of E=mc2

ASKER

@oBdA - Thanks so much.  How would I separate the emails in the destination .txt file?
Avatar of oBdA
oBdA

The usual: one address per line.
Avatar of E=mc2

ASKER

Thanks very much, this is exactly what I was looking for, spot on.