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

前端 未结 13 2073
一生所求
一生所求 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:22

    On a Windows 8.1 machine I got Send-MailMessage to send an email with an attachment through Gmail using the following script:

    $EmFrom = "user@gmail.com"
    $username = "user@gmail.com"
    $pwd = "YOURPASSWORD"
    $EmTo = "recipient@theiremail.com"
    $Server = "smtp.gmail.com"
    $port = 587
    $Subj = "Test"
    $Bod = "Test 123"
    $Att = "c:\Filename.FileType"
    $securepwd = ConvertTo-SecureString $pwd -AsPlainText -Force
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securepwd
    Send-MailMessage -To $EmTo -From $EmFrom -Body $Bod -Subject $Subj -Attachments $Att -SmtpServer $Server -port $port -UseSsl  -Credential $cred
    

提交回复
热议问题