Skip to content

Instantly share code, notes, and snippets.

@tillig
Created January 7, 2017 21:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tillig/cf95e3a75f138e26d8ddf22df04886e9 to your computer and use it in GitHub Desktop.
Save tillig/cf95e3a75f138e26d8ddf22df04886e9 to your computer and use it in GitHub Desktop.
Send an email via the Gmail SMTP server using Powershell
$From = "your-gmail-address@gmail.com"
$To = "the-destination-user@domain.com"
$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