I'm trying to access a SMTP remote server thru a remote shell using telnet and a command file command.txt containing command to send to that SMTP server as seen on https://tecadmin.net/ways-to-send-email-from-linux-command-line/# (note: that on the above website this is done interactivly) but here I want to do that inside a command file (I've just copied the yellow/red (the user input)) to the command file.
HELO yahoo.com
mail from: [email protected]
rcpt to: [email protected]
data
Hey
This is test email only
Thanks
.
quit
then using telnet IP smtp < command.txt always returns:
Trying 1.1.65.49...
Connected to 1.1.65.49.
Escape character is '^]'.
Connection closed by foreign host.
whereas when I do it interactily with:
perlhook@bbis:~/temp_25$ telnet 1.1.65.49 smtp
Trying 1.1.65.49...
Connected to 1.1.65.49.
Escape character is '^]'.
220 miraino-manabi.jp ESMTP Postfix
HELO yahoo.com
250 miraino-manabi.jp
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
554 5.7.1 <[email protected]>: Relay access denied
^]
telnet> quit
I get a return codes 220 250 554.
I'v also tried inside a here-doc shell script as following:
telnet 1.1.65.49 smtp <<END_SCRIPT
HELO yahoo.com
mail from: [email protected]
rcpt to: [email protected]
data
Hey
This is test email only
Thanks
.
quit
END_SCRIPT
and get the same results.
How can I get around this and make the script act as is it was interactive?