Telnet SMTP with attribute or shell script

advertisements

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"


You need to send a newline after sending "ehlo":

send "ehlo\n"

EDIT: Based on your latest edit, you also have to escape the leading bracket in your regex to prevent tcp from trying to interpret it as a command:

expect "\[2]{2,}\[0]{1,}"

EDIT: Also, your expect line isn't actually matching what you think it is. At this point, I'd suggest running through on of the many tutorials on expect, or simply use autoexpect to generate your script.