0

我尝试通过 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
4

1 回答 1

0

process_message()除了输出其输入数据之外什么都不做。因此,它会显示有关它收到的邮件的数据,但它不会将此邮件转发到您的真实收件箱,而是丢弃数据。

所以收不到邮件是正常的。

于 2012-09-27T11:32:57.367 回答