Send email from PowerShell

Sending an email from PowerShell

It’s easy to send an email from PowerShell, and it’s really useful for notifying yourself of the completion of a long-running script. It’s also a way to document what ran when, if you are like me and running hundreds of scripts and need a way to organize documentation on when you run things. Just alter the parameters below, and let ‘er rip and spam yourself!

param(  
[string] $From = "server@joelDomain.com",
[string] $To = "joelplaut@joelDomain.com",
[string] $Title = "title",
[string] $Body = "body"
)
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$SmtpServer = "mail.domainserver.com"
$SmtpClient.host = $SmtpServer 
$SmtpClient.Send($From,$To,$Title,$Body)
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *