我想在PowerShell发送的电子邮件中添加附件,但无法正常工作。
我试图将附件位置设置为变量,但是没有运气。
$EmailFrom = “Whatever@domain.com”
$EmailToAddresses = @(“email1”,"email2")
$Subject = “Your choice!”
$attachment = "C:\Users\simeo\Desktop\WebTest\Website_log.txt"
$Body = “The website is unreachable”
$SMTPServer = “smtp”
foreach ($EmailTo in $EmailToAddresses) {
$SMTPClient.Send($EmailFrom, $attachment, $EmailTo, $Subject, $Body)
}
我只想将电子邮件发送给多个带有日志文件附件的收件人。
答案 0 :(得分:0)
尝试以这种方式进行。当我使用它时效果很好。
.as-console-wrapper { max-height: 100% !important; top: 0; }
如上面评论中所述。
SmtpClient.Send方法具有
$EmailFrom = “Whatever@domain.com”
$EmailToAddresses = @(“email1”,"email2")
$Subject = “test!”
$attachment = "C:\files\file1.txt"
$Body = “test”
$SMTPServer = “Mail.smtp.com”
foreach ($EmailTo in $EmailToAddresses)
{
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -Attachments $attachment -SmtpServer $SMTPServer
}