I am trying to create a script to automatically send an email with various attachments. I am having an issue of the of it saying the file is not found. I can confirm that the file is present in the folder. I am unsure why I am getting this error and have tried running the script on various platforms thinking that it may be an issue of where the code is running but nothing has worked as of yet. Any help would be greatly appreciated.
Param (
$Path = "\\cottonwood\users\Shared\Pool Acquisitions",
$SMTPServer = "mail.genericmail.com",
$From = "address@genericmail.com",
#The below commented out line is used to test with just one individual. Be sure to comment out the one with all individuals before troubleshooting.
#$To = @("lt@genericmail.com"),
$SMTPport = "587",
$To = @("address@genericmail.com"),
$Subject = "Folders Added in",
$logname = "\\cottonwood\users\Shared\Loan Documents - Active\logs\New Folders$date.txt",
$date = (Get-Date -Format MMddyyyy),
$SMTPBody = "body",
$files = (Get-ChildItem "\\cottonwood\users\IT\Missing Folder Location")
)
$SMTPMessage = @{
To = $To
From = $From
Subject = "$Subject $Path"
Smtpserver = $SMTPServer
Port = $SMTPport
}
$attachment = $files
$SMTPBody = "`nThe following folders have been found to be non-existant in the last 24 hours:`n`n"
Send-MailMessage @SMTPMessage -Body $SMTPBody -Attachments $attachment