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! 🙂

Enjoy!
‘begin
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 = “smtprelayhost.com”

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(“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2 ‘SendUsingPort
‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = relayHost
‘Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate“) = cdoAnonymous
‘Your UserID on the SMTP server
‘objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername“) = “”
‘Your password on the SMTP server
‘objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword“) = “”
‘Server port (typically 25)
objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
‘Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpusessl“) = False
‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout“) = 20
objMessage.Configuration.Fields.Update
‘==End remote SMTP server configuration section==
objMessage.Send
‘end

Advertisements

~ by Jay P Morgan on January 14, 2011.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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