Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Trying to use Expect Script the Active TCL in Windows to send an email out every it is run. Below is the code I have but there is an error message displayed below and would appreciate any help on how to avoid the problem. Thank you.

#!/usr/bin/expect
# 
exec tclsh "$0" ${1+"$@"}
package require Expect

spawn plink -telnet IP PORT
send "ehlo *******.com
";
send "AUTH LOGIN
";
expect "334 VXNlcm5hbWU6" sleep .1;
send "*************
";
sleep .1;
expect "334 UGFzc3dvcmQ6
"
send "********
";
sleep .1;
expect "235 Authentication succeeded
";
send "MAIL from:******@*******.com
";
expect "250 OK
"
send "RCPT to:********@*********.com
";
expect "250 Accepted
"
send "DATA
";
send "!!!TEXT HERE!!!
";
send ".
";
send "QUIT
";
exit

Getting a error:

Error in startup script

send: spawn id exp2 not open
           while executing
"send "MAIL from:*****@******.com
""
   (file "***.tcl" line 16)

Any ideas on what is wrong here????

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
183 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think because the remote host closed the connection and plink exited.

Why don't you use the smtp package of tcllib? It is much easier to use than talking raw smtp over plink with expect.

To summarize: you use plink for telnet, a thing that you can do with tcl sockets already. You talk smtp, something where many libs exists that makes using it much easier.

Example of sending mail with pure tcl:

package require mime
package require smtp

set tok [::mime::initialize 
    -canonical text/plain 
    -header {From sender@address.example.com} 
    -string {Some Text Here}]
::smtp::sendmessage $tok 
    -servers IP 
    -ports PORT 
    -username ****** 
    -password ****** 
    -recipients recipient@address.example.com 
    -originator sender@address.example.com
::mime::finalize $tok

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...