Velocity Technical Archive
Sending an email with Powershell
Archived Reference: This is a historical technical article preserved from the Velocity Technologies knowledge base. For current Phoenix and East Valley managed IT services, explore our managed IT services or cybersecurity solutions.
$SmtpServer = "yourServer"\n$From = [email protected]\nif ($args.Length -lt 1) {\n $To = [email protected]\n}\nelse {\n $to = $args\n}\n$subject = "Need computer consulting"\n$Body = "Hi, this is John Doe I need cheap Exchange consulting at $125/hour"\n$smtpClient = new-object system.net.mail.smtpClient\n$smtpclient.host = $smtpServer\n$smtpclient.send($from, $to, $subject, $body)\n \n \nOnce this file is saved to ps1 format you can use it via this syntax\nTestMessage [email protected]