我正在尝试创建一个定期向我发送电子邮件的守护程序,并且我正在使用以下代码片段来执行此操作。
import smtplib
from datetime import date
from email.mime.text import MIMEText
def send_email():
SMTP_PORT = 587
SMTP_SERVER = 'smtp.mail.com'
SMTP_USERNAME = 'EMAIL'
SMTP_PASSWORD = 'PASSWORD'
EMAIL_TO = ['email@hotmail.com']
EMAIL_FROM = 'EMAIL'
EMAIL_SUBJECT = 'Test!'
DATE_FORMAT = '%d/%m/%Y'
EMAIL_SPACE = ', '
DATA='Email Content'
msg = MIMEText(DATA)
msg['Subject'] = EMAIL_SUBJECT + ' %s' % (date.today().strftime(DATE_FORMAT))
msg['To'] = EMAIL_SPACE.join(EMAIL_TO)
msg['From'] = EMAIL_FROM
mail = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
mail.starttls()
mail.login(SMTP_USERNAME, SMTP_PASSWORD)
mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
mail.quit()
但是,在5封电子邮件之后,即使我已将发件人电子邮件添加到outlook / hotmail上的联系人列表中,守护程序也会返回以下异常:
发送电子邮件! 1/1
Traceback (most recent call last):
File "daemon.py", line 91, in <module>
send_email()
File "daemon.py", line 78, in send_email
mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 742, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'email@hotmail.com': (550, 'Requested action not taken: mailbox unavailable\nFailure sending mail. Try again later')}
有人可以建议如何解决这个问题吗?有没有人知道一个已经过测试的电子邮件服务,它将允许超过5封电子邮件,或者我如何配置smtplib以便在5封电子邮件发送到同一地址后不停止发送?
更新:当我将接收电子邮件地址从outlook更改为gmail(我的另一封电子邮件)时 - 即使我没有向gmail SMTP服务器发送电子邮件,它也会返回相同的异常。