Created
January 7, 2017 21:12
-
-
Save tillig/cf95e3a75f138e26d8ddf22df04886e9 to your computer and use it in GitHub Desktop.
Send an email via the Gmail SMTP server using Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$From = "[email protected]" | |
$To = "[email protected]" | |
$Subject = "Email subject goes here" | |
$Body = "Email body goes here" | |
# The password is an app-specific password if you have 2-factor-auth enabled | |
$Password = "app-specific-password-here" | ConvertTo-SecureString -AsPlainText -Force | |
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password | |
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "smtp.gmail.com" -port 587 -UseSsl -Credential $Credential |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment