I copied and pasted this example and filled in my own email addresses.
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open('/Users/Jon/dev/iit/test-tools/logs/practice_tests.test_one.log', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()
me = 'Jon@MacBookPro.com'
you = 'jon.drowell@yahoo.com'
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of the log file'
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost', 1025)
s.sendmail(me, [you], msg.as_string())
s.quit()
I then opened another terminal window and ran the following command:
python -m smtpd -n -c DebuggingServer localhost:1025
When I run the file to send email, it finishes without error, and the terminal that is running the python -m smtpd -n -c DebuggingServer localhost:1025
command prints a nice log message that looks correct:
---------- MESSAGE FOLLOWS ----------
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: The contents of the log file
From: Jon@MacBookPro.com
To: jon.crowell@yahoo.com
X-Peer: 127.0.0.1
line one
line two
line three
------------ END MESSAGE ------------
But when I check my yahoo email address, the email never arrives. I have waited about 5 minutes, which I think is adequate. What did I do wrong?
From the smtpd documentation
class smtpd.DebuggingServer(localaddr, remoteaddr) Create a new debugging server. Arguments are as per SMTPServer. Messages will be discarded, and printed on stdout.