'PowerShell Email Multiple Recipients only sending to the last
I am writing a script to send emails to a manager and employee. I am creating a string of recipients, but when the send-mailmessaage runs it only sends to the last email on the string. Thus in the example it only sends to [email protected], and not [email protected]. I need it to send to both
$recipients = ''
if($usermanager.mail -ne $null){
$recipients = '' + $usermanager.mail + ''
}
if($userengineer.mail -ne $null){
$recipients += ', '+ $userengineer.mail + ''
}
#$Recipients now equals [email protected], [email protected]
Send-MailMessage -SMTPServer 'OUTLOOK-test.COM' -From 'test1, test1<[email protected]>' -To $recipients -Subject $subject -Body $emailBody -BodyAsHtml
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
