Telnet From a Batch File

Posted on 2009-04-29
Last Modified: 2012-05-06

From within a Windows 2003\XP batch (.bat). file I need to connect to a system using telnet then pass some commands.  I am trying to pipe the commands to a telnet session but am stuck (see code snippet).

I could be miles away from getting this to work or very close.

I cannot use vbscript or third party tools to do this.  It must all run from a batch file with no dependencies (other than being able to run telnet).

Can you please provide a code snippet to show how to pass commands to a telnet session?


@echo off

set EMAIL_CMD_FILE=c:\temp\mailsend.txt

set SMTP_IP=

set PORT=25




set DATA=This is a test.

:: Create Session Command File


echo helo %DOMAIN%

echo mail from: %EMAIL_FROM%


echo DATA

echo %DATA%

echo .

echo quit



echo %SESSION%

echo %SESSION% | telnet %SMTP_IP% %PORT%

Open in new window

Question by:michael4606
    LVL 22

    Expert Comment

    by:Adam Leinss
    You know that telnet is unencrypted, right?  And by telneting to a server or workstation over the Internet via telnet would send your password in cleartext?
    If you are VPNing in, just copy the batch file to \\targetcomputer\c$\somedir, then telnet in and run the batch file.
    LVL 1

    Accepted Solution

    Is it absolutely necessary you use a batch file? I've been using Febooti Command Line Email 2.0 under XP (they are up to 3.1 now, so I can't say if things have changed) as part of a script to send off an email for the past 2 years, and it has never forced me to register. There is a Febooti tagline at the bottom of the emails that are sent, but if that isn't bothersome to you, I'd check it out.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
    Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now