0

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.

3
  • Typically it would be HELO bob.example.org\r\n, and EHLO did replace HELO some number of years ago. It might be simpler to find code that already implements a SMTP client (or ESMTP client...). Commented Sep 26, 2022 at 20:33
  • It would be a good thing to tag the question with the language your code example is in (looks like python?) Do your 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. Commented Sep 26, 2022 at 20:59
  • the socket api isn't too hard, and is a good fit if all you are doing is running nc. Here is a link which has a simple client example how to send and receive docs.python.org/3/library/socket.html#example Commented Sep 26, 2022 at 21:53

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.