Skip to content

Instantly share code, notes, and snippets.

@kagarlickij
Created January 8, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagarlickij/2ca9d0cc59dd3c4e2caaf05ca68f3726 to your computer and use it in GitHub Desktop.
Save kagarlickij/2ca9d0cc59dd3c4e2caaf05ca68f3726 to your computer and use it in GitHub Desktop.
This script will send email via PowerShell
$From = "dmitriy@kagarlickij.com"
$To = "noreply@kagarlickij.com"
$Subject = "Test email from $hostname on $date"
$body = "Running on $hostname $date"
$Body += "<br>"
$Body += "<b><font color=green>Test</b></font> <br>"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$mailPass = Get-Content C:\Users\vagrant\MailboxSecurePass.txt | ConvertTo-SecureString
$mailCred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $From,$mailPass
Send-MailMessage -From $From -to $To -Subject $Subject `
-Body $Body -BodyAsHtml -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential $mailCred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment