0

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
Cameron B
  • 1
  • 1

1 Answers1

0

Send-MailMessage is unable to locate the files as the variable $files does not include the full file path

Change:

$files = (Get-ChildItem "\\cottonwood\users\IT\Missing Folder Location")

To:

$files = (Get-ChildItem "\\cottonwood\users\IT\Missing Folder Location").fullname
Itchydon
  • 2,572
  • 6
  • 19
  • 33