PowerShell v1.0: Script to send email messages

$smtpServer = "192.68.4.2"
$smtpFrom = [email protected]
$smtpTo = "[email protected]"
$messageSubject = “Automation: Output Report ”
$messageBody = “Script Completed successfully without any errors.”

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody)

 

If you specify an incorrect SMTP server, you’ll end up receiving the below error message:

PS C:> powershell.exe C:TestSend-Emails.ps1
Exception calling "Send" with "4" argument(s): "Failure sending mail."
At C:TestSend-Emails.ps1:29 char:19
+         $smtp.Send( <<<< $smtpFrom,$smtpTo,$messagesubject,$messagebody)
Mail already sent to [[email protected]]

Leave a Reply

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