问题描述
我正在使用python脚本来使用Amazon Simple Email Service向400个用户动态发送HTML电子邮件。该脚本使用openpyxl从Excel文件中读取电子邮件地址。
但是该脚本在发送时随机崩溃约260至280个用户。我当前的解决方法是将Excel文件设置在脚本先前崩溃的位置,然后再次运行它。有我的代码:
import email.utils
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('alternative')
msg['From'] = sender_email
msg['Subject'] = 'Your email subject'
context = ssl.create_default_context()
server = smtplib.SMTP_SSL(smtp_server,port,context=context)
server.login(smtp_login,password)
for dest_email in email_list:
message_html = '<html><head><title></title></head><body>Dynamic content here...</body></html>'
message_plain = 'Content here...'
part1 = MIMEText(message_plain,'plain')
part2 = MIMEText(message_html,'html')
msg.attach(part1)
msg.attach(part2)
server.sendmail(sender_email,dest_email,msg.as_string())
server.close()
我试图在执行过程中捕获异常,但是我在这里没有太多关于发生问题的细节:
- 异常 :( 554,b'事务处理失败:MIME部分计数超过 500。')
- msg.items():[('Content-Type','multipart / alternative; boundary =“ =============== 2309883816392967535 ==”'),('MIME-Version', '1.0'),('发件人','发件人[email protected]'),('主题', “您的主题”)]
我已经看了一段时间,但无法解决这个问题。你能帮我解决这个问题吗?我究竟做错了什么?发送成功的电子邮件后,是否需要重新设置标题?让我知道您是否需要其他详细信息。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)