Imap.vbs - Monitoring IMAP mail server availability using ActiveXperts Network Monitor
ActiveXperts Network Monitor ships with a powerful set of pre-defined checks.
Each individual check has a static number of configuration items.
To monitor other items, or to combine monitoring items, you can make use of custom VBScript checks.
Most of the built-in checks have a VBScript equivalent, implemented as a Function in a VBScript (.vbs) file.
Out-of-the-box, each VBScript function monitors the same items as the built-in check. Feel free to modify a function.
The VBScript check can be customized by editing the VBScript function.
To add a new VBScript-based IMAP monitoring check, do the following:
- On the 'Monitor menu', click 'New Monitoring Check (VBScript)'. The 'VBScript Check' dialog box appears;
- In the 'File selection box', select 'Email.vbs';
- In the 'Function selection box', select 'CheckImap';
- In the 'Function parameters group box' enter the required parameters. You can also load a working sample first by clicking on the 'Load a sample, click here' link.
To customize the above monitoring check, click on the 'Edit button' next to the 'File selection box'. Notepad will be launched. You can now make changes to the VBScript
function(s).
Email.vbs script source code
' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor - VBScript based checks
' // © ActiveXperts Software B.V.
' //
' // For more information about ActiveXperts Network Monitor and VBScript, please
' // visit the online ActiveXperts Network Monitor VBScript Guidelines at:
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' //
' ///////////////////////////////////////////////////////////////////////////////
'
Option Explicit
Const retvalUnknown = 1
Dim SYSDATA, SYSEXPLANATION ' Used by Network Monitor, don't change the names
' //////////////////////////////////////////////////////////////////////////////
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following 5 lines:
' Dim bResult
' bResult = CheckSmtp( "smtp.activexperts-labs.com" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
' ////////////////////////////////////////////////////////////////////////////////////////
' //////////////////////////////////////////////////////////////////////////////
Function CheckSmtp( strSmtpServer )
' Description:
' Establish a telnet session to an SMTP mail server and validate its response
' SMTP servers always reply a '220' message when ready to establish a session
' This function uses the Network Component, an ActiveXperts product.
' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
' For more information about Network Component, see: www.activexperts.com/network-component
' Parameters:
' 1) strSmtp - Host name or IP address of the mail server
' Usage:
' CheckSmtp( "" )
' Sample:
' CheckSmtp( "smtp.activexperts-labs.com" )
CheckSmtp = retvalUnknown ' Default return value
SYSDATA = "" ' Not used by this function
SYSEXPLANATION = "" ' Set initial value
CheckSmtp = checkTelnet( strSmtpServer, 25, "", "", "", "220" )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function CheckPop3( strPop3Server )
' Description:
' Establish a telnet session to a POP3 mail server and validate its response
' POP3 servers always reply a '+OK' message when ready to establish a session
' This function uses the Network Component, an ActiveXperts product.
' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
' For more information about Network Component, see: www.activexperts.com/network-component
' Parameters:
' 1) strPop3Server - Host name or IP address of the mail server
' Usage:
' CheckPop3( "" )
' Sample:
' CheckPop3( "pop3.activexperts-labs.com" )
CheckPop3 = retvalUnknown ' Default return value
SYSDATA = "" ' Not used by this function
SYSEXPLANATION = "" ' Set initial value
CheckPop3 = checkTelnet( strPop3Server, 110, "", "", "", "+OK" )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function CheckImap( strImapServer )
' Description:
' Establish a telnet session to an IMAP mail server and validate its response
' IMAP servers always reply a 'IMAP' message when ready to establish a session
' This function uses the Network Component, an ActiveXperts product.
' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
' For more information about Network Component, see: www.activexperts.com/network-component
' Parameters:
' 1) strImapServer - Host name or IP address of the mail server
' Usage:
' CheckImap( "" )
' Sample:
' CheckImap( "imap.activexperts-labs.com" )
CheckImap = retvalUnknown ' Default return value
SYSDATA = "" ' Not used by this function
SYSEXPLANATION = "" ' Set initial value
CheckImap = checkTelnet( strImapServer, 143, "", "", "", "IMAP" )
End Function
' //////////////////////////////////////////////////////////////////////////////
' //
' // Private Functions
' // NOTE: Private functions are used by the above functions, and will not
' // be called directly by the ActiveXperts Network Monitor Service.
' // Private function names start with a lower case character and will
' // not be listed in the Network Monitor's function browser.
' //
' //////////////////////////////////////////////////////////////////////////////
' //////////////////////////////////////////////////////////////////////////////
Function checkTelnet( strServer, numPort, strCommand1, strCommand2, strCommand3, strReceive )
Dim objTcp, strAllResponses
checkTelnet = 1 ' Default return value
SYSDATA = "" ' Not used by this function
SYSEXPLANATION = "" ' Set initial value
Set objTcp = CreateObject("ActiveXperts.Tcp")
objTcp.Protocol = 2 ' 1 means: raw, 2 means: telnet (see also Network Component manual)
objTcp.Connect strServer, numPort
If( objTcp.LastError <> 0 Or objTcp.ConnectionState <> 3 ) Then
checkTelnet = False
SYSEXPLANATION = "Unable to connect to [" & strServer & "]"
objTcp.Disconnect ' can be called even when there's no connection
Exit Function
End If
objTcp.Sleep( 2000 ) ' Allow some time
tcprecv objTcp, strAllResponses
tcpsend objTcp, strCommand1
tcprecv objTcp, strAllResponses
tcpsend objTcp, strCommand2
tcprecv objTcp, strAllResponses
tcpsend objTcp, strCommand3
tcprecv objTcp, strAllResponses
If( InStr( UCase( strAllResponses ), UCase( strReceive ) ) <> 0 ) Then
checkTelnet = True
Else
checkTelnet = False
End If
SYSEXPLANATION = "Response=[" & strAllResponses & "]"
objTcp.Disconnect
End Function
' //////////////////////////////////////////////////////////////////////////////
Sub tcpsend( objTcp, strCommand )
If( strCommand <> "" ) Then
objTcp.SendString( strCommand )
End If
End Sub
' //////////////////////////////////////////////////////////////////////////////
Sub tcprecv( objTcp, BYREF strAllResponses )
Dim bHasData, strResponse
bHasData = objTcp.HasData
While( bHasData )
strResponse = objTcp.ReceiveString()
bHasData = objTcp.HasData
If( strAllResponses <> "" ) Then
strAllResponses = strAllResponses & ".." ' .. to indicate a newline
End If
strAllResponses = strAllResponses & strResponse
WEnd
End Sub