email-pop3.ps1 - powershell script by ActiveXperts Software
email-pop3.ps1 checks a POP3 server by login in
Use email-pop3.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select email-pop3.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-pop3.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-Pop3.ps1
# Description:
# Logon to a POP3 mail server, either secure or not secure, using an POP3
# account and password
# This function uses ActiveXperts Mobile Messaging Component.
# ActiveXperts Mobile Messaging Component is automatically licensed when ActiveXperts Network Monitor is purchased.
# For more information about ActiveXperts MobileMessaging 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 110 for non-secure servers, 995 for secure servers
# 3) bIsSecure - Secure server or not
# 4) strPop3Account - Account name to logon to smtp server
# 5) strPop3Password - Password to logon to smtp server
# Usage:
# .\Email-Pop3 '<Hostname | IP>' <Port-Number> <IsSecure> '<Account>' '<Password>'
# Sample:
# .\Email-Pop3 'pop3.activexperts.com' 110 '$false' 'yourname' 'yourpassword'
#################################################################################
# -- Declare Parameters
param( [string]$strHost = '', [int]$nPort = -1, [string]$bIsSecure = $false, [string]$strPop3Account = '', [string]$strPop3Password = '' )
# -- 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 -or $strPop3Account -eq '' -or $strPop3Password -eq '' )
{
$res = 'UNCERTAIN: Invalid number of parameters - Usage: .\Email-Pop3.ps1 <Hostname | IP>" <Port-Number> <IsSecure> "<Account>" "<Password>"'
echo $res
exit
}
$objPop3 = new-object -comobject AxMmToolkit.Pop3
if( $bIsSecure -eq $true )
{
$objPop3.SetSecure( $nPort )
}
else
{
$objPop3.HostPort = $nPort
}
$objPop3.Connect( $strHost, $strPop3Account, $strPop3Password )
if( $objPop3.LastError -ne 0 )
{
$res = 'ERROR: Failed to connect to [' + $strHost + '], error #' + $objPop3.LastError + ': ' + $objPop3.GetErrorDescription( $objPop3.LastError )
echo $res
exit
}
# -- Print script result
$res = 'SUCCESS: Response from [' + $strHost + ']: [' + $objPop3.LastPop3Response + ']'
echo $res
$objPop3.Disconnect()
#################################################################################
# // --- Catch script exceptions ---
#################################################################################
trap [Exception]
{
$res = 'UNCERTAIN: ' + $_.Exception.Message
echo $res
exit
}
