【发布时间】:2020-02-02 05:36:21
【问题描述】:
当我使用标准的 smtplib.SMTP.sendmail 函数时,我可以使用 email.utils.formataddr(senderName, local-part@domain) 作为 from_addr 来调用它,以在电子邮件客户端中显示发件人的姓名。
当我使用twisted.mail.smtp.sendmail 做同样的事情时,我得到的是local-part,而不是senderName。
到目前为止,我只在 Gmail 中对此进行了测试,但由于这是我公司使用的,所以这是我的要求的一部分。
我尝试通过 twisted.mail.smtp.sendmail 发送格式化地址,但出现解析错误。
我使用了 twisted.mail.smtp.quoteaddr,但发现它只是将格式化的名称和地址剥离回地址。不过没有解析错误。
#print('populate the message')
msg = MIMEMultipart('alternative')
msg["Subject"] = 'A Subject'
msg["From"] = email.utils.formataddr(('Sender Name', 'noreply@example.com'))
msg["Reply-to"] = 'noreply@example.com'
msg["To"] = 'recipient@example.com'
content = MIMEText("Hey, what's up?" ,"html")
msg.attach(content)
msg_timeout = round(float(30))
# create the sender and send it
result = twisted.mail.smtp.sendmail("mail-sc", msg["From"], msg["To"].split(","), msg,
port=25, requireAuthentication=False)
收到此错误失败:twisted.mail._except.AddressError:在'' of ('"Sender Name"', ['', ''])
【问题讨论】:
标签: python email smtp twisted mime