How Do You Automate a telnet Session to Send a Postfix Email on a Linux Server?

Problem scenario
You want to create a script that will send an email from a Linux server. You want it to use telnet. How do you automatically send an email using telnet?

Set up Postfix. If you are running SUSE, see this posting. If you are running a RedHat derivative, see this posting.

Use this script, but change the email addresses before you run it. is the email that you want the email to appear to be from. is the email address that you are sending to.


HOST=$(hostname -f)' 25'
CMD1='mail from:'
CMD2='rcpt to:'
CMD4='basic text here'
echo open "$HOST"
sleep 2
echo "$CMD1"
echo "$CMD2"
echo "$CMD3"
echo "$CMD4"
echo "$CMD5"
echo "$CMD6"
sleep 2
echo "exit"
) | telnet

An Alternative Way To Send Email
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.

Leave a comment

Your email address will not be published. Required fields are marked *