Click here to Skip to main content
13,627,571 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


12 bookmarked
Posted 7 Mar 2007
Licenced CPOL

Sending Emails Using VBScript and NetCat

, 7 Mar 2007
Rate this:
Please Sign up or sign in to vote.
To complement my earlier post on sending emails using JScript and Netcat, here is the same but using VBScript and showing the translation from JScript to VBScript.


A little while ago, I wrote a post on how to send an email using JScript and the very useful program - NetCat. This post covers the same ground, but in VBScript, and compares the code in the two languages.

The original post is here and also on 'The Code Project' here.

I find that JScript is easier to work in JScript than VBScript for most of the stuff I do; however, many people prefer VBScript. The snag is that Microsoft does not seem to be putting much effort into supporting VBScript; they have not even created (as far as I know) a .NET version of it. I guess this means that there is some benefit in VBScripters being about to code in JScript as well. To that end, I have not only given and discussed the VBScript source here, but also shown (in comments) the JScript of the original. I hope that those less familiar with JScript can see that it is really very similar to VBScript once you've gotten over all those wiggly brackets!

How Does it Work

I have already discussed interacting with Web Services using the XMLHTTP object. For sending email, there is no such ready made object to help us. However, sending email is not an especially complex matter, so we can just use NetCat instead!

To do this, you will first require a copy of NetCat. I have a copy that runs on Windows XP from here. I did not do the port, but the credits are in the zip, and it is GPL 2. Once you have nc.exe, you will need to put it somewhere on the executable path (e.g., system32) or in the same directory in which you are going to run your script.

The script should be run by cscript from the command prompt. You will have to change the address of the SMTP server to one for which you have access, and set the to and from email addresses, hit count, and inter-hit delay to the appropriate settings. This is a real script, I used it today to load test an email server!

'var strExe = "nc -v 25";
dim strExe
strExe = "nc -v 25"

'var objShell = WScript.CreateObject("WScript.Shell");
dim objShell
set objShell = WScript.CreateObject("WScript.Shell")

'var total  = 8;
dim total
total  = 8

'var delay  = 0;
dim delay
delay  = 0

'var victim = "";
dim victim
victim = ""

'for(var i=0;i<total;++i)
dim i
for i=1 to total

'    var strExeIn ="HELO\r\n"; 
'        strExeIn+="MAIL FROM: <>\r\n";
'        strExeIn+="RCPT TO: <"+victim+">\r\n";
'        strExeIn+="DATA\r\n";
'        strExeIn+="Body of email: this is an auto generated test email.\r\n";
'        strExeIn+="This is "+(i+1)+" of "+total+"\r\n";
'        strExeIn+=".\r\n";
'        strExeIn+="QUIT\r\n";

    dim strExeIn
    strExeIn =            "HELO" + vbcrlf
    strExeIn = strExeIn + "MAIL FROM: <>" + vbcrlf
    strExeIn = strExeIn + "RCPT TO: <"+victim+">" + vbcrlf
    strExeIn = strExeIn + "DATA"+ vbcrlf
    strExeIn = strExeIn + _
               "Body of email: this is an auto generated test email." + _
    strExeIn = strExeIn + "This is " & i & " of " & total & vbcrlf
    strExeIn = strExeIn + "." + vbcrlf
    strExeIn = strExeIn + "QUIT" + vbcrlf
    'var objScriptExec = objShell.Exec(strExe);
    dim objScriptExec
    set objScriptExec = objShell.Exec(strExe)



    'WScript.echo("Sending "+(i+1)+" of "+total+" to "+victim);
    WScript.echo("Sending " & i & " of " & total & " to "+victim)




For loads more on VBScript, see the VBScript section of Nerds-Central.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

alex turner
Web Developer
United Kingdom United Kingdom
I am now a Software Systems Developer - Senior Principal at Micro Focus Plc. I am honoured to work in a team developing new compiler and runtime technology for Micro Focus.

My past includes a Ph.D. in computational quantum mechanics, software consultancy and several/various software development and architecture positions.

For more - see



You may also be interested in...


Comments and Discussions

GeneralDownload Problems Fix Pin
alex turner21-Jan-10 2:59
memberalex turner21-Jan-10 2:59 
GeneralFile download Pin
Smitha Vijayan18-Jan-10 11:43
editorSmitha Vijayan18-Jan-10 11:43 
GeneralRe: File download Pin
alex turner18-Jan-10 22:22
memberalex turner18-Jan-10 22:22 
GeneralSending Emails Pin
DAYCODE12-Mar-07 7:26
memberDAYCODE12-Mar-07 7:26 
GeneralRe: Sending Emails Pin
alex turner12-Mar-07 7:35
memberalex turner12-Mar-07 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.180712.1 | Last Updated 7 Mar 2007
Article Copyright 2007 by alex turner
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid