Sending an email with Powershell

$SmtpServer = “yourServer”
$From = me@N2NetworkSolutions.com
if ($args.Length -lt 1) {
     $To = Engineers@N2NetworkSolutions.com
}
else {
     $to = $args[0]
}
$subject = “Need computer consulting”
$Body = “Hi, this is John Doe I need cheap Exchange consulting at $125/hour”
$smtpClient = new-object system.net.mail.smtpClient
$smtpclient.host = $smtpServer
$smtpclient.send($from, $to, $subject, $body)
 
 
Once this file is saved to ps1 format you can use it via this syntax
TestMessage Sales@N2NetworkSolutions.com

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply