Telnet From a Batch File

Hello,

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?

Thanks,

Michael
@echo off
 
set EMAIL_CMD_FILE=c:\temp\mailsend.txt
 
set SMTP_IP=192.168.1.42
set PORT=25
set DOMAIN=mycompany.net
set EMAIL_FROM=me@mycompany.com
set EMAIL_TO=joe@mycompany.com
set DATA=This is a test.
 
:: Create Session Command File
(
echo helo %DOMAIN%
echo mail from: %EMAIL_FROM%
echo RCPT TO: %EMAIL_TO%
echo DATA
echo %DATA%
echo .
echo quit
) > %EMAIL_CMD_FILE%
set /p SESSION="" < %EMAIL_CMD_FILE%
 
echo %SESSION%
echo %SESSION% | telnet %SMTP_IP% %PORT%

Open in new window

michael4606Asked:
Who is Participating?
 
batch2Connect With a Mentor Commented:
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.

http://www.febooti.com/products/command-line-email/
0
 
Adam LeinssSenior Desktop EngineerCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.