Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

REQ : Example smtp telnet batch script.

4,512 views
Skip to first unread message

Bastiaan van Haastrecht

unread,
Jan 16, 2003, 7:10:55 AM1/16/03
to
Hi,

Does anyone have a example how to send a plain text email with a batch
script using the windows telnet.exe

I came up with this, but it doesnt enter the text when connected to the smtp
server.

telnet post.demon.com 25
EHLO someone.com
MAIL FROM: som...@anotherdomain.com
RCPT TO: in...@someothertdomain.com
DATA
This is the text of the message
.
QUIT


Thanks in advance, Bas.


William Allen

unread,
Jan 16, 2003, 7:35:05 AM1/16/03
to
"Bastiaan van Haastrecht" wrote in message

> Does anyone have a example how to send a plain text email with a batch
> script using the windows telnet.exe
>
> I came up with this, but it doesnt enter the text when connected to the smtp
> server.

The standard Windows TelNet client is not directly scriptable.

There are three approaches you might consider:
(1) Use a command-line emailer
(2) Script TelNet with WSH (Windows Script Host)
(3) Use a scriptable TelNet client

Further details:

(1) Use a command-line emailer

Try BLAT from: http://www.interlog.com/~tcharron/blat.html

Quoted from there: "Blat is a Public Domain Windows 95/NT console
utility that sends the contents of a file in an e-mail message using the
SMTP protocol. Blat is useful for creating scripts where mail has to be
sent automatically (CGI, backups, etc.), or just as a quick way to send
a file or message quickly from the command line. It will store relevant
configuration details in the registry for ease of use. Optionally, blat
can also attach multiple binary files to your message. "

(2) Script TelNet with WSH (Windows Script Host)

You can use the SendKeys method of WSH to script any Windows
program, such as TelNet.EXE - this is a demo Batch file showing
the syntax to use for Windows 95/98/ME. The demo opens the TelNet
client and connects to the remote system. You will need to add
suitable SendMail or other commands. See Note 1 for details of
Microsoft Windows Script Host and where to obtain upgrades.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

:: Extract VBS code from this script to temporary VBS workfile
%COMSPEC%/c %0 GOTO: _TELNET ECHO.>{TEMP}.VBS

:: Open a Telnet window - it will be the window with focus
start /r TELNET.EXE

:: Run the script to send keys to Telnet window
cscript//nologo {TEMP}.VBS

:: Clear away workfile
DEL {TEMP}.VBS

GOTO EOF (=Subroutine section below=)
:_TELNET (Usage: %COMSPEC%/c %0 GOTO: _TELNET ECHO.)
%3set sh=WScript.CreateObject("WScript.Shell")
%3WScript.Sleep 1000
%3sh.SendKeys "%%C" % Send Alt-C for menu item Connect %
%3WScript.Sleep 1000
%3sh.SendKeys "R" % R for sub-item Remote system %
%3WScript.Sleep 1000
%3sh.SendKeys "some.telnet.site" % Send Host Name %
%3WScript.Sleep 1000
%3sh.SendKeys "%%C" % Alt-C to press Connect button %

:EOF (End-of-file)

====End cut-and-paste (omit this line)
Win9x GUI study/demo only. Cut-and-paste as Batch script (file with .BAT
extension). Lines that don't begin with 2 spaces have wrapped by mistake.

(3) Use a scriptable TelNet client

You could try the Tera Term (originally commercial software) scriptable
Telnet client. This is now freeware (but with no support). The Zip
package includes several example Macros, including one for automatic
login to a remote server (LOGIN.TTL). The package includes an
explanation of the Tera Term macro language.

The package includes instructions to associate Macro files with the
Macro execution module, so you can run an entire automated Telnet
session by double-clicking a Macro file if you wish.

Tera Term ZIP package from:
http://hp.vector.co.jp/authors/VA002416/teraterm.html

--
William and Linda Allen
Learn to write Batch Files on your Win95/98/ME PC. Free, interactive
Web Course. Syllabus and Index to Lessons: http://www.allenware.com/

Note 1

WSH (Windows Script Host) enables routine tasks to be handled in either
VBScript or JScript. It's available as a free downloadable add-on for
the tiny proportion of Windows machines (mostly older Windows 95 ones)
which don't already have it (in one version or another). Documentation
is included as an HTML help file, and includes cut-and-pastable syntax
examples in VBScript and JScript for all features.

Windows Script Host information/upgrade-to-current-version/downloads:
http://msdn.microsoft.com/scripting/

By default, WSH installs CSCRIPT.EXE which is a Batch file
interface allowing all WSH functionality to be run from a normal
DOS-style Batch file. This interface provides Windows machines
with a massive extension to the traditional Batch functionality.


andrewk...@ev1.net

unread,
Jan 16, 2003, 9:23:20 AM1/16/03
to

I have dl Blat and found it difficult to use, and could not get anyone to
help with it.
0 new messages