Last active
January 14, 2020 15:16
-
-
Save ivangeorgiev/9ed4bf3e42070e05011b4fc70d53ecf6 to your computer and use it in GitHub Desktop.
Send Email from 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
# https://docs.microsoft.com/en-us/previous-versions/powershell/module/Microsoft.PowerShell.Utility/Send-MailMessage?view=powershell-5.0 | |
$smtp = "smtp.office365.com" | |
$username = "username here ..." | |
$passwordText = "password here ..." | |
$from = $username | |
$to = $username | |
$password = ConvertTo-SecureString $passwordText -AsPlainText -Force | |
$cred = New-Object System.Management.Automation.PSCredential ($username, $password) | |
$body = “Just a test email” | |
Send-MailMessage -To $to -from $from -Subject 'test' -Body $body -BodyAsHtml -smtpserver $smtp -usessl -Credential $cred -Port 587 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment