期望脚本Telnet电子邮件脚本 [英] Expect Script Telnet email script

查看:277
本文介绍了期望脚本Telnet电子邮件脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Expect脚本编写Windows中的活动TCL,以在每次运行时发送电子邮件.以下是我拥有的代码,但是下面显示了一条错误消息,希望您能对如何避免此问题有所帮助.谢谢.

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\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)

这里有什么问题的想法吗??

Any ideas on what is wrong here????

推荐答案

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

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

为什么不使用tcllib的smtp软件包? 比起通过带有预期的plink的原始smtp来使用它要容易得多.

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

总结:您将plink用于telnet,这已经可以使用tcl socket来完成. 您说的是smtp,其中存在许多库,这使使用它变得更加容易.

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.

使用纯tcl发送邮件的示例:

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

这篇关于期望脚本Telnet电子邮件脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆