email-smtp.ps1 - powershell script by ActiveXperts Software
email-smtp.ps1 checks an SMTP server by login in
Use email-smtp.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select email-smtp.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
email-smtp.ps1 script code
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com # Last Modified: like vbs ################################################################################# # Script: # Email-Smtp.ps1 # Description: # Logon to an SMTP mail server, either secure or not secure, optionally using # an SMTP account and password # SMTP servers always reply a '220' message when ready to establish a session # ActiveXperts Mobile Messaging Component is automatically licensed when ActiveXperts Network Monitor is purchased. # For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component # Declare Parameters: # 1) strHost - Host name or IP address of the mail server # 2) nPort - Port number of the mail server. Default 25 for non-secure servers, 465 for secure servers # 3) bIsSecure - Secure server or not # 4) strSmtpAccount - Account name to logon to smtp server # 5) strSmtpPassword - Password to logon to smtp server # Usage: # .\Email-Smtp.ps1 '<Hostname | IP>' <Port-Number> <IsSecure> '<Account>' '<Password>' # Sample: # .\Email-Smtp.ps1 'smtp.activexperts-labs.com' 25 '$false' '' '' ################################################################################# # -- Declare Parameters param( [string]$strHost = '', [int]$nPort = -1, [string]$bIsSecure = $false ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Validate parameters, return on parameter mismatch if( $strHost -eq '' -or $nPort -lt 0 ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\Email-Smtp.ps1 "<Hostname | IP>" <Port-Number> <IsSecure> "<Account>" "<Password>"' echo $res exit } $objSmtp = new-object -comobject AxMmToolkit.Smtp if( $bIsSecure -eq $true ) { $objSmtp.SetSecure( $nPort ) } else { $objSmtp.HostPort = $nPort } $objSmtp.Connect( $strHost, $strSmtpAccount, $strSmtpPassword ) if( $objSmtp.LastError -ne 0 ) { $res = 'ERROR: Failed to connect to [' + $strHost + '], error #' + $objSmtp.LastError + ': ' + $objSmtp.GetErrorDescription( $objSmtp.LastError ) echo $res exit } # -- Print script result $res = 'SUCCESS: Response from [' + $strHost + ']: [' + $objSmtp.LastSmtpResponse + ']' echo $res $objSmtp.Disconnect() ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }