28 Oct 2011

Sending email using GMail account in powershell


This is an example code to send an email using GMail account in Powershell.

"border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;">
            #send email            
            $smtpServer = "smtp.gmail.com"
            $smtp = new-object Net.Mail.SmtpClient($smtpServer, 587)
            $smtp.EnableSsl = $true
            $smtp.Credentials = new-object System.Net.NetworkCredential("","");
            $smtp.Send($fromAddr, $toAddr, $subject, $body)
            "Email Sent"

0 comments:

Post a Comment