2017-07-07 209 views
0

我想創建一個腳本來自動發送帶有各種附件的電子郵件。我有一個問題說它沒有找到該文件。我可以確認該文件存在於該文件夾中。我不確定爲什麼我得到這個錯誤,並試圖在各種平臺上運行腳本,認爲它可能是代碼運行的問題,但目前還沒有任何工作。任何幫助將不勝感激。Powershell電子郵件附件

Param (
    $Path = "\\cottonwood\users\Shared\Pool Acquisitions", 
    $SMTPServer = "mail.genericmail.com", 
    $From = "[email protected]", 
    #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 = @("[email protected]"), 
    $SMTPport = "587", 
    $To = @("[email protected]"), 
    $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

Send-MailMessage無法找到這些文件作爲變量$files不包括完整的文件路徑

變化:

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

要:

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