Want to build up a Auth Smtp Connection with expect script... just to test I wanted to get ehlo parameters but expect is not working like this
#!/usr/bin/expect
set timeout -1
set smtp [lindex $argv 0]
set port [lindex $argv 1]
spawn telnet $smtp $port
expect "[2]{2,}[0]{1,}"
send "ehlo\n"
I expect the code 220 to come from mailserver to continue to send ehlo ... just like
..../...:telnet smtp.mail.yahoo.de 25
Trying 77.238.184.85...
Connected to smtp2-de.mail.vip.ukl.yahoo.com.
Escape character is '^]'.
220 smtp116.mail.ukl.yahoo.com ESMTP
ehlo
250-smtp116.mail.ukl.yahoo.com
250-AUTH LOGIN PLAIN XYMCOOKIE
250-PIPELINING
250-SIZE 41697280
250 8BITMIME
error saying:
spawn telnet smtp.mail.yahoo.de 25
invalid command name "2"
while executing
"2"
invoked from within
"expect "[2]{2,}[0]{1,}""
(file "./login.exp" line 6)
if I just write expect "220" instead of expect "[2]{2,}[0]{1,}" it works but ignors send "ehlo\n"
As above adviced I used exp_internal 1 to get sense of what expects really listen to... Also I can recommend autoexpect which created the expect script not perfectly but after improving some codings it is a real help and at last it worked.
#!/usr/bin/expect
#exp_internal 1
set timeout -1
set smtp [lindex $argv 0]
set port [lindex $argv 1]
spawn telnet $smtp $port
expect -re {[2]{2,}[0]{1,}}
sleep 3;
send -- "Ehlo\r"
expect -re {[2]{1,}[5]{1,}[0]{1,}}
send -- "quit\r"
expect eof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With