我使用下面的脚本从powershell脚本发送电子邮件。
$smtpServer = "mail.company.com"
$smtpFrom = "Check <check@company.com>"
$smtpTo = "user1@company.com"
$messageSubject = "Daily Check from $thedate"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$message.Body = $Body | ConvertTo-HTML -head $style -body $Body
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
它工作正常,直到我添加更多这样的reciepients ...
$smtpTo = "user1@company.com", "user2@company.com"
我也尝试将它放在像这样的数组中....
$smtpTo = @("user1@company.com", "user2@company.com")
它们都不适合我。希望有人可以提供帮助
答案 0 :(得分:2)
System.Mail.MailMessage is a collection that you can add emails to的.To
属性。
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$Message.to.add('myotheremail@mydomain.net')
$message.Subject = $messageSubject
$message.IsBodyHTML = $true