gpt4 book ai didi

python - 通过smtplib发送邮件时如何在邮件内容中添加href链接

转载 作者:太空狗 更新时间:2023-10-29 18:30:25 27 4
gpt4 key购买 nike

我正在通过以下代码发送电子邮件:

msg = MIMEText(u'<a href="www.google.com">abc</a>')
msg['Subject'] = 'subject'
msg['From'] = 'xxx'
msg['To'] = 'xxx'

s = smtplib.SMTP(xxx, 25)
s.sendmail(xxx, xxx, msg.as_string())

我想收到的是

abc

我实际收到的是:

<a href="www.google.com">abc</a>

最佳答案

您应该指定 'html'作为子类型 -

msg = MIMEText(u'<a href="www.google.com">abc</a>','html')

如果不单独指定子类型,子类型默认为'plain'(纯文本)。来自 documentations -

class email.mime.text.MIMEText(_text[, _subtype[, _charset]])

A subclass of MIMENonMultipart, the MIMEText class is used to create MIME objects of major type text. _text is the string for the payload. _subtype is the minor type and defaults to plain.

(强调我的)。

关于python - 通过smtplib发送邮件时如何在邮件内容中添加href链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31715138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com