Currently, I am working on a project where I use telnet to netcat to send an email message within my university.
I am trying to make the process automated but my script can't seem to enter in any commands after I connect to the mail server (MX). Here is what I have so far.
import subprocess
status = subprocess.Popen('nc mx0a-00164701.pphosted.com 25', stdin=subprocess.PIPE, shell=True)
output = status.communicate(input=b'helo Bob')
But the helo Bob command never gets read and the rest of my script never gets executed. When I look at the result in my terminal, I get a 220 connection success message for the mx server connection.
HELO bob.example.org\r\n, andEHLOdid replaceHELOsome number of years ago. It might be simpler to find code that already implements a SMTP client (or ESMTP client...).b'...'strings send a carriage return / line feed pair of characters as specified in the SMTP prototol RFCs? A lack of expected command termination characters could prevent the SMTP server from knowing when your command is complete and it's safe to parse it and respond.