-1

尝试在 Windows 中使用 Expect Script the Active TCL 以在每次运行时发送一封电子邮件。下面是我拥有的代码,但下面显示了一条错误消息,希望能提供有关如何避免该问题的任何帮助。谢谢你。

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

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

收到错误:

Error in startup script

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

关于这里有什么问题的任何想法????

4

1 回答 1

5

我认为是因为远程主机关闭了连接并且 plink 退出了。

为什么不使用smtptcllib 的包呢?它比通过 plink 与 expect 交谈原始 smtp 更容易使用。

总结一下:您将 plink 用于 telnet,您socket已经可以使用 tcl s 来做这件事。你说的是 smtp,其中存在许多库,这使得使用它变得更加容易。

纯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
于 2013-02-04T20:49:34.817 回答