I have a small application under Linux to receive an email with the use of smtpd.SMTPServer. Here is the small test code:
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
print 'Receiving message from:', peer
print 'Message addressed from:', mailfrom
print 'Message addressed to :', rcpttos
print 'Message length :', len(data)
return
server = CustomSMTPServer(('0.0.0.0', 25), None)
asyncore.loop()
I have the following issues: (1) When using this piece of code, the computer sending the email gets the following message: 502 Error: command "EHLO" not implemented so the server cannot reply correctly to receive further data / communicate with the email-sending computer (which I assume is the client).
Shouldn't such a basic thing like EHLO be implemented in a Ubuntu installation in the first place? Why is it not implemented?
(2) I figured that EHLO can be installed by installing postfix in Ubuntu. I did that and the same test call went on, but stopped later with a different error:
Client: RCPT TO: XXX@YYY.com
Server: 554 5.7.1 <XXX@YYY>: Relay access denied
(3) At later times, after doing some more other tests, I got the error from the test code itself:
error: [Errno 98] Address already in use
It turns out that the used IP address was already in use as could be seen with
netstat -lnpt
of which the case was the running postfix. After stopping the postfix service the address was no longer in use, but of course it was back to issue #1:
502 Error: command "EHLO" not implemented
I would like to be able to use a SMTPServer to receive an email message 1. without the need to install postfix 2. with the use of asyncore
If there are any ideas of how to make this possible in an easy and simple way using python libraries that would be great!
Cheers Alex
Try this. Of course, it does not implement the EHLO command, but makes it treat it the same as the HELO command. Of course, it might only get you past the first stumbling block, however if the rest of the smtp commands are compatible it might get you by:
You will probably find the smtpd.py file in /usr/lib/python2.7
Also, I note the python3.5 version of the same library looks like it supports EHLO, so maybe you could try and use python3. But apparently python3 is not backwards compatible it seems - so good luck.
1) Postfix is an SMTP server, it has nothing to do with python's
smtpd
EHLO implementation. If you want your custom SMTP server, you don't need postfix, so feel free to remove it.2)
EHLO
is aESMTP
command, notSMTP
, standardsmtpd
python module implementsSMTP
, therefore it doesn't have anEHLO
implementation.