If you start a local server as follows:
python -m smtpd -n -c DebuggingServer localhost:1025
Make sure to modify the mail-sending code to use the non-standard port number:
server = smtplib.SMTP(SERVER, 1025)
server.sendmail(FROM, TO, message)
server.quit()