Sending an email from python using smtpd.DebuggingServer as STMP server

email, python, smtpd, smtplib

Solution

According to python documentation on the smtpd module:

class smtpd.DebuggingServer(localaddr, remoteaddr)
    Create a new debugging server. Arguments are as per SMTPServer. 
    Messages will be discarded, and printed on stdout.

So the module doesn't actually send an email. It prints it in the terminal.

Problem

I'm trying to send an email using Python and used the following code: ``` import smtplib import datetime SERVER = "localhost" PORT = 1025 FROM = "me@mydevice.com" TO = ["myemailaddress@something.com"] SUBJECT = "test" dt = datetime.datetime.now() TEXT = "blabla bla @ " + str(dt) message = """\ From: %s To: %s Subject: %s %s """ % (FROM, ",".join(TO), SUBJECT, TEXT) server = smtplib.SMTP(SERVER, PORT) server.sendmail(FROM, TO, message) server.quit() ``` Not having any STMP server already installed/setup, I simply used this: ``` python -m smtpd -n -c DebuggingServer localhost:1025 ``` The code seems to run fine, no errors, and the server even notifies me with this: ``` ---------- MESSAGE FOLLOWS ---------- From: me@mydevice.com To: myemailaddress@something.com Subject: test X-Peer: 127.0.0.1 blabla bla @ 2014-01-29 14:44:37.219724 ------------ END MESSAGE ------------ ``` `'myemailaddress@something.com'` is, of course, a representation of a real, existing email address while `'me@mydevice.come'` is made up. But no email arrives at myemailaddress@something.com... Am I missing something obvious here? I read somewhere (sorry but cannot find it anymore) that services likes gmail may well block emails coming from non-static IP addresses. Could that be what is going on here?

Original source