【问题标题】:In Python's smtplib package, is there a way to create a notification if sent emails bounce?在 Python 的 smtplib 包中,有没有办法在发送的电子邮件退回时创建通知?
【发布时间】:2019-01-25 13:29:32
【问题描述】:

目前,我正在使用 Python 的 smtplib 包发送电子邮件。我有大量的电子邮件,我想验证它们是否存在。在大多数情况下,获得 250 条消息就足够了。但是,对于 aol.com,您可以放置​​任何句柄,他们仍然会说它存在。

因此,我正在一条一条地发送消息。有没有办法编写一个例程,如果一封电子邮件没有通过,smtplib 会通知我这封无效的电子邮件?谢谢!

【问题讨论】:

    标签: python email email-validation smtplib


    【解决方案1】:

    如果无法发送电子邮件,则会引发异常as per the docs。您可以执行以下操作:

    cantSendErrors = (smptlib.SMTPHeloError, smptlib.SMTPSenderRefused)  # Put any other suitable exceptions in this tuple
    try:
        smptlib.sendmail(args, go, here)
    except cantSendErrors:
        # Your code here. You could email yourself or write the error to log file for later review, your choice.
    

    【讨论】:

    • 谢谢,您知道如何提取退回的电子邮件吗?
    • @user321627 在你的代码中你肯定会有一个变量来引用失败的电子邮件,甚至是它的内容,这应该足够了吗?
    猜你喜欢
    • 2014-01-31
    • 2020-07-09
    • 2017-03-15
    • 2011-09-28
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2021-06-19
    • 2023-04-09
    相关资源
    最近更新 更多