Click here to Skip to main content
6,294,871 members and growing! (17,202 online)
Email Password   helpLost your password?
Languages » VBScript » General     Intermediate

Sending Emails Using VBScript And NetCat

By alex turner

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
VBScript, Windows, Dev
Posted:7 Mar 2007
Views:23,136
Bookmarked:9 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
0 votes for this article

A little time ago I wrote a post on how to send an email using VBScript 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 than VBScript for most of the stuff I do; however, many people prefer VBScript. The snag is that Microsoft do 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 in somewhere on the executable path (e.g. system32) or in the same directory in which you are going to run your script.

The 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 appropriate settings. This is a real script, I used it today to load test an email server!

'var strExe = "nc -v smtp.gotadsl.co.uk 25";

dim strExe
strExe = "nc -v smtp.gotadsl.co.uk 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 = "ian.manson@project-network.com";

dim victim
victim = "git@cubicalland.com"

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

dim i
for i=1 to total

'    var strExeIn ="HELO nerds-central.com\r\n"; 

'        strExeIn+="MAIL FROM: <test@nerds-central.com>\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 nerds-central.com" + vbcrlf
    strExeIn = strExeIn + "MAIL FROM: <test@nerds-central.com>" + vbcrlf
    strExeIn = strExeIn + "RCPT TO: <"+victim+">" + vbcrlf
    strExeIn = strExeIn + "DATA"+ vbcrlf
    strExeIn = strExeIn + "Body of email: this is an auto generated test email." + vbcrlf
    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)

    'objScriptExec.StdIn.write(strExeIn);

    objScriptExec.StdIn.write(strExeIn)

    'objScriptExec.StdIn.close();

    objScriptExec.StdIn.close()

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

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

    'WScript.echo(objScriptExec.StdOut.ReadAll());

    WScript.echo(objScriptExec.StdOut.ReadAll())

    'WScript.sleep(delay);

    WScript.sleep(delay)

next

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

alex turner


Member
I started out as a Chemist, but just keep being pulled back into IT.

I am now a senior architect with The Project Network (www.project-network.com)
Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular VBScript articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralSending Emails PinmemberDAYCODE8:26 12 Mar '07  
GeneralRe: Sending Emails Pinmemberalex turner8:35 12 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Mar 2007
Editor:
Copyright 2007 by alex turner
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project