Avatar of E=mc2
E=mc2
Flag for Canada

asked on 

How can I change this script so that it can send out emails using Outlook365?

Good day.
I would like to change this powershell script to enable me to send an email with an attachment out from a computer.
I am not sure that the reference to the smtp for office 365 is correct.
And I also feel that port 587 and TLS is a requirement, however I am not sure.

Any helps is greatly appreciated.
Regards,


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

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

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'report@mail.com' -To 'joe@mail.com' `
  -SmtpServer 'smtp.office365.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\123.pdf'
 ###PROGRAM END###
PowershellMicrosoft OfficeMicrosoft 365

Avatar of undefined
Last Comment
Pber

8/22/2022 - Mon