我尝试通过 python 发送电子邮件。根据我的脚本发送成功。
import smtplib
sender = 'from@fromdomain.com'
receivers = ['my@emailadress.com']
message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('127.0.0.1', 1025)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except smtplib.SMTPException:
print "Error: unable to send email"
但是当我检查我的电子邮件时,我没有收到新邮件。:(问题出在哪里?我发送的电子邮件在哪里?
编辑:
我的 smtp 测试服务器是:
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', 1025), None)
print "Started...."
asyncore.loop()
我的 smtp 服务器说:
Receiving message from: ('127.0.0.1', 65071)
Message addressed from: from@fromdomain.com
Message addressed to : ['my@emailadress.com']
Message length : 129