Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python SMTP Server Not Receiving Emails

Tags:

python

email

smtp

I've tried running a simple python SMTP server but for some reason it won't receive any incoming emails when I send it to the server. I'm using the following code from https://pymotw.com/2/smtpd/index.html:

import smtpd
import asyncore

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(('127.0.0.1', 25), None)

asyncore.loop()

And I'm running the script with: sudo python simpleSmtpServer.py

A few notes:

  • I'm running this script on an AWS EC-2 Instance
  • I know that I set up my MX records properly; I've tried running a simple smtp server using Mailin (https://github.com/Flolagale/mailin) with nodejs and it's able to receive and display the test emails I send it

Is there anything I'm missing with this code or maybe some DNS configurations that I need to update?

like image 805
Copernicus Avatar asked Nov 16 '25 11:11

Copernicus


1 Answers

@furas had the answer. Changing the address to 0.0.0.0 fixed the problem.

like image 103
Copernicus Avatar answered Nov 19 '25 02:11

Copernicus



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!