Powershell send-mailmessage - email to multiple recipients

前端 未结 7 2059
小蘑菇
小蘑菇 2020-11-29 07:10

I have this powershell script to sending emails with attachments, but when I add multiple recipients, only the first one gets the message. I\'ve read the documentation and s

相关标签:
7条回答
  • 2020-11-29 07:45

    here is a full (gmail) and simple solution... just use normal ; delimiter.. best for passing in as params.

    $to = "user1@domain.org;user2@domain.org"
    $user = "italerts@domain.org"    
    $pass = ConvertTo-SecureString -String "pass" -AsPlainText -Force
    
    $cred = New-Object System.Management.Automation.PSCredential $user, $pass
    $mailParam = @{
        To = $to.Split(';')
        From = "IT Alerts <italerts@domain.org>"
        Subject = "test"
        Body = "test"
        SmtpServer = "smtp.gmail.com"
        Port = 587
        Credential = $cred
    }
    
    Send-MailMessage @mailParam -UseSsl
    
    0 讨论(0)
提交回复
热议问题