比方說,你在被覆蓋的類處理消息,如:如何拒絕smtpd.SMTPServer.process_message中的收件人?
class MailProcessorServer(smtpd.SMTPServer):
def process_message(self, peer, sender, rcpttos, data):
badrecipients = []
for rcpt in rcpttos:
badrecipients.append(rcpt)
#Here I want to warn the sender via a bounced email
# that the recipient does not exist
raise smtplib.SMTPRecipientsRefused(badrecipients)
#but this just crashes the process and eventually the sender times out,
# not good enough
我只想馬上退回給發件人。相反,發送服務(比如GMail)最終放棄並在幾個小時後警告用戶。 documentation似乎很稀疏。
+1的鏈接來源 – nalply 2011-05-17 07:45:13