Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to test SMTP port using VBScript?

I need to test several servers to verify that the SMTP service is accepting connections on port 25. I prefer to do this using a VBScript. I would also prefer to do this without the need for commercial software. I am well versed in VBScript and not easily stumped, however I am at wits end. Any help is appreciated.

Update:

Since this script is for work and licensing compliance is VERY important here, hacking the MS Winsock control included with VS is not a viable option. Any other ideas would be great.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    If Visual Studio is installed on the box where you'll be running the script you can use the following:

    Option Explicit

    Const sckClosed= 0

    Const sckOpen= 1

    Const sckListening= 2

    Const sckConnectionPending= 3

    Const sckResolvingHost= 4

    Const sckHostResolved= 5

    Const sckConnecting= 6

    Const sckConnected= 7

    Const sckClosing= 8

    Const sckError= 9

    Dim sock, started

    Set sock = CreateObject("MSWinsock.Winsock")

    sock.Connect "mailserver", 25

    started = Now()

    Do While sock.State <> sckConnected And sock.State <> sckError

    If DateAdd("s", 10, started) < Now() Then

    Exit Do

    End If

    WScript.Sleep 100

    Loop

    Select Case sock.State

    Case sckConnected

    MsgBox "Connected"

    Case sckError

    MsgBox "Can't connect"

    Case Else

    MsgBox "Unexpected state - " & sock.State

    End Select

    sock.Close

    If Visual Studio is not present, the script will fail when it tries to do CreateObject("MSWinsock.Winsock"). If this is the case, you can download the OCX available at http://www.gurgensvbstuff.com/index.php?ID=27 and modify the code as they suggest.

  • 1 decade ago

    Just pay a professional man.

    They are broke.

    Or uh... hmm.

    Yeah just pick the guy above me thats smarter.

    Source(s): I dont know a Computer from an Amiga cartridge.
Still have questions? Get your answers by asking now.