Script to test SMTP relay from Windows host

This has helped me more than once, so I thought I’d share.  Most of the code probably came from MSDN, which is a great resource.

Copy the following into a text file, from “‘begin” to “‘end”.
Save the text file as sendmail.vbs (or anythingyoulike.vbs)
Run it from the box that should use SMTP relay!

Answer the prompts. CC is optional, just press enter to leave it blank.

Optionally, you can autopopulate the fields and skip the prompts if you understand the VBS. That is the simplest part, really.  If you administer windows boxes and don’t know VBScript, learn it! 🙂

Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 ‘Do not authenticate
Const cdoBasic = 1 ‘basic (clear-text) authentication
Const cdoNTLM = 2 ‘NTLM
Const relayHost = “”

Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = inputbox(“Subject?”,”SendMail”)
objMessage.From = inputbox(“From?”,”SendMail”)
objMessage.To = inputbox(“To?”,”SendMail”)
objMessage.CC = inputbox(“CC”,”SendMail”) ‘Can be left blank
objMessage.TextBody = inputbox(“Body?”,”SendMail”)

‘==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item(““) = 2 ‘SendUsingPort
‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item(““) = relayHost
‘Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item(““) = cdoAnonymous
‘Your UserID on the SMTP server
‘objMessage.Configuration.Fields.Item(““) = “”
‘Your password on the SMTP server
‘objMessage.Configuration.Fields.Item(““) = “”
‘Server port (typically 25)
objMessage.Configuration.Fields.Item(““) = 25
‘Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item(““) = False
‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item(““) = 20
‘==End remote SMTP server configuration section==


~ by Jay P Morgan on January 14, 2011.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s