当我使用标准 smtplib.SMTP.sendmail 函数时,我可以使用 email.utils.formataddr(senderName, local-part@domain) 作为 from_addr 来调用它,以在电子邮件客户端中显示发件人的姓名。
当我使用twisted.mail.smtp.sendmail 做同样的事情时,而不是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:在''的解析错误('“发件人名称”',['','<','noreply','@','发件人','。' ,'com', '>'])
森栏
相关分类