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!

  1. WScript.Echo EMail( "TEST SENDER <[email protected]>", _
  2. "TEST RECEIPIENT <[email protected]>", _
  3. "Hi", _
  4. "This is a test message", _
  5. "", _
  6. "", _
  7. "your.local.or.remote.server.fqdn.local", _
  8. 25 )
  9.  
  10. Function EMail( myFrom, myTo, mySubject, myTextBody, myHTMLBody, myAttachment, mySMTPServer, mySMTPPort )
  11. Dim i, objEmail
  12. On Error Resume Next
  13. Set objEmail = CreateObject( "CDO.Message" )
  14. With objEmail
  15. .From = myFrom
  16. .To = myTo
  17. .Subject = mySubject
  18. .Textbody = myTextBody
  19. .HTMLBody = myHTMLBody
  20. If IsArray( myAttachment ) Then
  21. For i = 0 To UBound( myAttachment )
  22. .AddAttachment Replace( myAttachment( i ), "\", "\\" ),"",""
  23. Next
  24. ElseIf myAttachment <> "" Then
  25. .AddAttachment Replace( myAttachment, "\", "\\" ),"",""
  26. End If
  27. If mySMTPPort = "" Then
  28. mySMTPPort = 25
  29. End If
  30. With .Configuration.Fields
  31. .Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2
  32. .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = mySMTPServer
  33. .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = mySMTPPort
  34. .Update
  35. End With
  36. .Send
  37. End With
  38. If Err Then
  39. EMail = "ERROR " & Err.Number & ": " & Err.Description
  40. Err.Clear
  41. Else
  42. EMail = "Message sent ok"
  43. End If
  44. Set objEmail = Nothing
  45. On Error Goto 0
  46. End Function