我正在尝试创建一个脚本来自动发送包含各种附件的电子邮件。我有一个问题,说没有找到该文件。我可以确认该文件存在于该文件夹中。我不确定为什么我收到此错误,并尝试在各种平台上运行脚本,认为它可能是代码运行的地方的问题,但尚未发生任何工作。任何帮助将不胜感激。
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
答案 0 :(得分:0)
Send-MailMessage
无法找到文件,因为变量$files
不包含完整的文件路径
变化:
$files = (Get-ChildItem "\\cottonwood\users\IT\Missing Folder Location")
要:
$files = (Get-ChildItem "\\cottonwood\users\IT\Missing Folder Location").fullname