Hans Raj wrote:

Actually I tried to read the servers response after sending each line, but the
"gets $s_ptr" command just hangs. (I do get a response to HELO, and but not after other commands). Any thoughts on this?

You'll need to flush the buffer after every other line, too.

fconfigure $s_ptr -buffering line

might be more what you want than having to always call flush.

Actually, the lines you're
sending are not quite correct either.

> Which ones?

RFC 2821 � 4.1.1: "SMTP commands are character strings terminated by <CRLF>." If you want Tcl to use CRLF at the end of each line, not just LF, use the command:

fconfigure $s_ptr -translation {crlf crlf}

� 4.1.1.1: "A client SMTP SHOULD start an SMTP session by issuing the EHLO command." So you should use EHLO, not HELO, although this isn't strictly required.

Additionally, the field following HELO or EHLO "contains the fully-qualified domain name of the SMTP client if one is available." Something like [lindex [fconfigure $s_ptr -sockname] 1] should be close enough.

� 4.1.1.2: The MAIL FROM syntax is:

"MAIL FROM:" ("<>" / Reverse-Path)

Reverse-Path is eventually defined in � 4.1.2 as:

"<" Local-part "@" Domain ">"

In other words, the destination address must be surrounded by angle brackets. The same goes from RCPT TO in � 4.1.1.3.

� 2.3.1 makes it clear that the message data is an email messages as described in RFC 2822, which defines the headers in particular. The Date and From headers are required, with a blank line before the message itself. There are also restrictions on just what characters may appear in what headers.

Why not use the "smtp" package from Tcllib to do it properly?

http://www.tcl.tk/software/tcllib/


I'm using the TCL shell in a Communications testset, and it doesnt have the
required packages/libraries installed. It offers just basic functionality.

There's a lot required to send an email message via SMTP correctly, although sendmail tends to make things easy for you. You'd be better off using a platform where you can install Tcllib, or use Python and smtplib, or Perl and Net::SMTP.

The reason I dint try to make the code very robust is that this email-capablity
is not a critical (or even a nescessary) part of the script. Just put it in to
let me know the status of a test-script if run over the weekend. However, I would be grateful for any suggestions/tips.

As Jim points out, you can easily connect to a server running Netcat or similar tools. The minimal HTTP request is much simpler than SMTP, too, so you could write a CGI program that waits for a certain request from your program, which could even be written in sh. Tcl 8.0 and later come with a simple HTTP client library to make it even easier.

----------
#!/bin/sh
mail -s "Status: $*" [EMAIL PROTECTED] < /dev/null
----------

--
"Hanging is too good for a man who makes puns; he should be drawn and quoted."
-- Fred Allen

Attachment: signature.asc
Description: OpenPGP digital signature



Reply via email to