Solved

Telnet batch file needed

Posted on 2004-03-23
13
57,230 Views
Last Modified: 2013-12-19
i need a batch file that will open a telnet conenction and send an email via an smtp server.  for example i want to send an email to me@mydomain.com via 10.10.10.10 with a short message.  if there is a way to call a seperate text file (like FTP batch files) that holds the body of the email that would be great.
0
Comment
Question by:xxgenius
  • 3
  • 2
  • 2
  • +5
13 Comments
 
LVL 11

Expert Comment

by:nazirahmed
ID: 10662659
Hi
try this:

telnet mail.domain.ext 25
MAIL FROM: mail@domain.ext
RCPT TO: mail@otherdomain.ext
DATA
Subject:-type subject here- then press enter twice
(the actual message)
hello mail@otherdomain.ext from mail@domain.ext

QUIT

hope it will help
0
 
LVL 3

Expert Comment

by:wei2ali
ID: 10665258
I've tried to create smtp-batch files when making network montoring utilities, but found it cumbersome. Instead, there's a utility called BLAT, which I found useful. Here's the link (http://www.blat.net). It takes a half hour to get familar with the software, but after that, you can't live without it ;)
0
 
LVL 8

Author Comment

by:xxgenius
ID: 10667119
nazirahmed, thanks but i already know how to telnet and send a message.  what i need is a batch file that run from a script.

wei2ali, i need this to be executed from a script triggered by sendmail.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 3

Expert Comment

by:wei2ali
ID: 10667587
Here's a piece of code I used in a web-check utility. You don't have to know KiXtart (though you'll definitely gonna love it). The purpose to to show you how to embed/pass parameters to Blat.exe when scripting

Function SendMail($subj, $msg, Optional $ExchangeServer)
      $msg = "_test_"
      $subj = '"Test, ignore please"'
      $Sender = "somebody@@mysite.local"
      $rcp1 = "somebody1@@mysite.local"
      $rcp2 = "somebody2@@mysite.local"      
      $ExchangeServer = "Your_server_NETBIOS_NAME or IP"
      shell '%comspec% /c Blat $msg -f $Sender -t $rcp1,$rcp2 -server $ExchangeServer -s $subj -q'
Endfunction

You can pass parameters to the function from script, or simply get familar with the shel command line swithces of Blat. I'll try to explain this line closer:
      shell '%comspec% /c Blat $msg -f $Sender -t $rcp1,$rcp2,$rcp3 -server $ExchangeServer -s $subj -q'

Let's start with "Blat $msg". I suppose you've got regular messages to send depending on the output of your script, $msg points to the message you want to send, it can be a file or standard output from the script.
   -f: server
   -t: recepient(s)
   -server: self-explanary
   -s: subject (Always needs to be in quotation marks!)
   -q: No error message output

0
 
LVL 11

Expert Comment

by:nazirahmed
ID: 10670084
xxgenius
cant you copy code to a script file and run it through batch file.or simply copy the code into a file named yourscript.txt and run
ftp -s:yourscript.txt
0
 
LVL 11

Accepted Solution

by:
nazirahmed earned 500 total points
ID: 10731857
sorry xxgenius..i made a mistake when i said "ftp -s:yourscript.txt", you dont need to go through ftp...but through telnet...
normally you cant logon to telnet using a script or batch file.
i think the following link will help you
http://expect.nist.gov
http://bmrc.berkeley.edu/people/chaffee/expectnt.html
another option could be to use some terminal emulation programs, like
http://www.ericom.com/
but i am afraid you cant logon to telnet with a script or batch file.

0
 

Expert Comment

by:gfarnham
ID: 12035240
You might try Telnet Scripting Tool
http://www.freewareweb.com/cgi-bin/archive.cgi?ID=645
It is simple and I think does what you are looking for.
0
 

Expert Comment

by:j0ri
ID: 15020475
I have almost the same problem as xxgenius.
This is the situation:
I have to test +- 40 servers on mail relay. So my idea was to send a mail through each server with a batch script to myself. My idea was the following:

telnet <server A> 25
HELO jori.knops@gmail.com
MAIL FROM: jori.knops@gmail.com
RCPT TO: jori.knops@gmail.com
DATA: test mail to server A
.
quit

telnet <server B> 25
HELO jori.knops@gmail.com
MAIL FROM: jori.knops@gmail.com
RCPT TO: jori.knops@gmail.com
DATA: test mail to server B
.
quit

This way i know which server relays mail and which server doesn't (if I receive a mail with "test mail to server B" I know that server B relays).

When i follow these steps manualy, it works perfectly but when I try to do this with the script he only logs in to the first server but doesn't give the HELO command (and all the commands after HELO). When I type the rest of the commands manualy (HELO, MAIL FROM, etc) and type quit, the script logs me in on the next server. So he only does the telnet <server A/B> 25 command.

I've allready tried the links that you guys posted, but I can't figure out how those programs work.
0
 

Expert Comment

by:lelton
ID: 15103211
I have the same problem. I need to issue an ETRN command to some of our mail servers every half our or so.

telnet mail.domain.com 25
ETRN domain.com

Its very simple, I don't even need to login. But I don't seem to be able to run a telnet command from a batch file, that I could simply schedule.

Any (simple) ideas, this will be running on a server, so I really don't want to add any software to a stable machine.

Les Elton,
Network Admin., ABC Recycling Ltd
0
 

Expert Comment

by:j0ri
ID: 15105222
i solved my problem using a combination of blat ( http://www.blat.net/ ) and a batch script.

it basicly looked like this:
script:
blat <mail addresses, server_1 address, etc, etc>
blat <mail addresses, server_2 address, etc, etc>
etc

so if blat knows the command that you want to use, it's easy to solve it.

i'll see if i can upload my script somewhere :)
0
 
LVL 4

Expert Comment

by:rickybsb
ID: 23439100
Yes, you can do a telnet script, as simple as ftp scripting.
If you are using *nix, try:
#!/bin/bash
(
echo YOURLOGIN;
sleep 2;
echo YOURPASSWORD;
sleep 1;
echo YOURTELNETCOMMAND1
sleep 1;
echo YOURTELNETCOMMAND2
echo exit
) | telnet 192.168.6.254
0
 

Expert Comment

by:kp397
ID: 23624907
Hi.
I'm also looking to execute telnet commands from the wondows batch. if you have any ideas, let me know.
0
 
LVL 4

Expert Comment

by:rickybsb
ID: 33386492
On Windows, using Teraterm pro you can easily do telnet command batch scripting

Just fire it up from the CMD:

ttpmacro.exe YOURSCRIPT.TXT

Example of YOURSCRIPT.TXT:

------------------------------------------------
connect '200.1.2.3.4'
UsernamePrompt = 'Login:'
Username = 'admin'
PasswordPrompt = 'Password:'
loginpass = 'YOURPASSWORD'
wait   UsernamePrompt
sendln Username
wait   PasswordPrompt
sendln loginpass
wait '>'
pause 5
sendln 'Yourfirst Telnet Command'
sendln 'Your second telnet command'
sendln 'Any number of telnet commands on each line'
sendln '/'
sendln 'quit'
-------------------------------
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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