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)

Comments

Popular posts from this blog

SharePoint 2013: Error updating managed account credentials

How can I call a JIRA api through Powershell?