Not able to pass Username and Password in telnet session

I have created a shell script to telnet remote machine. Here is the problem I am not able to pass the login username and password to the telnet session. I have searched forum and got few other methods to achieve this. But I need to know what's wrong in the below script.

username="root"
password="password"
telnet 102.240.101.223
spawn
expect "login:"
send $username
expect "password:"
send $password
send "exit"
expect eof 

Thanks in advance

How about:

username="root"
password="password"
telnet 102.240.101.223
spawn
expect "login:"
send "$username\r"
expect "password:"
send "$password\r"
send "exit\r"
expect eof

Same Result. username and Password are not passed to the telnet sessions. Script requires user to enter username and password manually.