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

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

    I used Christian's Feb 12 solution and I'm also just beginning to learn PowerShell. As far as attachments, I was poking around with Get-Member learning how it works and noticed that Send() has two definitions... the second definition takes a System.Net.Mail.MailMessage object which allows for Attachments and many more powerful and useful features like Cc and Bcc. Here's an example that has attachments (to be mixed with his above example):

    # append to Christian's code above --^
    $emailMessage = New-Object System.Net.Mail.MailMessage
    $emailMessage.From = $EmailFrom
    $emailMessage.To.Add($EmailTo)
    $emailMessage.Subject = $Subject
    $emailMessage.Body = $Body
    $emailMessage.Attachments.Add("C:\Test.txt")
    $SMTPClient.Send($emailMessage)
    

    Enjoy!

提交回复
热议问题