Monday, 22 July 2013

Send an Email form PowerShell using Google SMTP

The following code snippet will send an email from PowerShell using Googles SMTP server.

$EmailFrom="blah@gmail.com"
$EmailTo = "blah2@uxceclipse.com"
$Subject = "Test"
$Body = "Test Body"
$SMTPServer = "smtp.gmail.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("blah@gmail.com", "Password");
$SMTPClient.Send($SMTPMessage)

No comments:

Post a Comment