我正在使用 Python 向 gmail 帐户发送电子邮件。这是我正在使用的代码
msg = email.mime.multipart.MIMEMultipart()
msg['From'] = 'myemail@gmail.com'
msg['To'] = 'toemail@gmail.com'
msg['Subject'] = 'HTML test'
msg_html = email.mime.text.MIMEText('<html><head></head><body><b>This is HTML</b></body></html>', 'html')
msg_txt = email.mime.text.MIMEText('This is text','plain')
msg.attach(msg_html)
msg.attach(msg_txt)
#SNIP SMTP connection code
smtpConn.sendmail('myemail@gmail.com', 'toemail@gmail.com', msg.as_string())
当我在 gmail 中查看这封电子邮件时,HTML 和文本版本都显示如下:
这是 HTML
这是文字
它应该是显示文本或 html,这是导致此行为的原因。