Skip to main content

Test an SMTP server using a vbs script

Have you ever got to the situation where you have an open relay in IIS or any other smtp server and you want to make sure that it works ? Here is a nice vbs script that does just that. Just replace the email addresses, server and port , save the contents as yourfile.vbs and run it!

[vb]
WScript.Echo EMail( "TEST SENDER <anyusername@youdomain.com>", _
"TEST RECEIPIENT <yourusername@yourdomain.com>", _
"Hi", _
"This is a test message", _
"", _
"", _
"your.local.or.remote.server.fqdn.local", _
25 )

Function EMail( myFrom, myTo, mySubject, myTextBody, myHTMLBody, myAttachment, mySMTPServer, mySMTPPort )
Dim i, objEmail
On Error Resume Next
Set objEmail = CreateObject( "CDO.Message" )
With objEmail
.From = myFrom
.To = myTo
.Subject = mySubject
.Textbody = myTextBody
.HTMLBody = myHTMLBody
If IsArray( myAttachment ) Then
For i = 0 To UBound( myAttachment )
.AddAttachment Replace( myAttachment( i ), "\", "\\" ),"",""
Next
ElseIf myAttachment <> "" Then
.AddAttachment Replace( myAttachment, "\", "\\" ),"",""
End If
If mySMTPPort = "" Then
mySMTPPort = 25
End If
With .Configuration.Fields
.Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = mySMTPServer
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = mySMTPPort
.Update
End With
.Send
End With
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "Message sent ok"
End If
Set objEmail = Nothing
On Error Goto 0
End Function
[/vb]