Send mail via Gmail with PowerShell V2's Send-MailMessage

前端 未结 13 2052
一生所求
一生所求 2020-11-30 21:07

I\'m trying to figure out how to use PowerShell V2\'s Send-MailMessage with Gmail.

Here\'s what I have so far.

$ss = New-Object Security         


        
13条回答
  •  一向
    一向 (楼主)
    2020-11-30 21:21

    Here's my PowerShell Send-MailMessage sample for Gmail...

    Tested and working solution:

    $EmailFrom = "notifications@somedomain.com"
    $EmailTo = "me@earth.com"
    $Subject = "Notification from XYZ"
    $Body = "this is a notification from XYZ Notifications.."
    $SMTPServer = "smtp.gmail.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password");
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
    

    Just change $EmailTo, and username/password in $SMTPClient.Credentials... Do not include @gmail.com in your username...

提交回复
热议问题