I try to do a script to send mail to multiple recipients.
I trace to a file the -To parameter and it looks OK, but when I send the mail only the second recipient receives the mail.
My script:
$mailAddress = $DDSTab2.$clef
$date = Get-Date
Add-Content -Path $LogFile -Value "$date - $Fichier - $mailAddress"
Here is example output from the log file:
08/29/2017 12:02:13 - PV_00049521_2841_DGFIP_93.pdf - < test@live.com>,< test2@live.com>
This doesn't work:
Send-MailMessage -From "dgfip@toto.com" -To $mailAddress -Subject "PV $Fichier" -SmtpServer "192.168.40.252" -Body "Veuillez trouver ci-joint le PV de raccordement. Cordialement" -Attachments $PV
But when I put the literal recipients it does work:
Send-MailMessage -From "dgfip@toto.com" -To <test1@live.com>,<test2@live.com> -Subject "PV $Fichier" -SmtpServer "192.168.40.252" -Body "Veuillez trouver ci-joint le PV de raccordement. Cordialement" -Attachments $PV
And it works. I can't understand the problem!