Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving email with SMTPServer in python:

Tags:

python

smtp

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: [email protected]
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

like image 939
Alex Avatar asked Dec 17 '25 22:12

Alex


1 Answers

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 a ESMTP command, not SMTP, standard smtpd python module implements SMTP, therefore it doesn't have an EHLO implementation.

like image 186
favoretti Avatar answered Dec 19 '25 12:12

favoretti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!