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

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

    Here it is:

    $filename = “c:\scripts_scott\test9999.xls”
    $smtpserver = “smtp.gmail.com”
    $msg = New-Object Net.Mail.MailMessage
    $att = New-Object Net.Mail.Attachment($filename)
    $smtp = New-Object Net.Mail.SmtpClient($smtpServer )
    $smtp.EnableSsl = $True
    $smtp.Credentials = New-Object System.Net.NetworkCredential(“username”, “password_here”); # Put username without the @GMAIL.com or – @gmail.com
    $msg.From = “username@gmail.com”
    $msg.To.Add(”boss@job.com”)
    $msg.Subject = “Monthly Report”
    $msg.Body = “Good MorningATTACHED”
    $msg.Attachments.Add($att)
    $smtp.Send($msg)
    

    Let me know if it helps you San. Also use the send-mailmessage also at Www.techjunkie.tv

    For that way also that I think is way better and pure to use.

提交回复
热议问题