Sunday, March 22, 2020

Sending email via Microsoft PowerShell

I rarely use PowerShell, but this is a very useful script for testing SMTP.

$EmailFrom = “”
$EmailTo = “”
$Subject = “The subject of your email”
$Body = “What do you want your email to say”
$SMTPServer = “”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Credit to the author of this over at

No comments:

Post a Comment