我正在使用Python向一个Gmail账户发送电子邮件。这是我使用的代码。
当我在Gmail中查看此电子邮件时,HTML和文本版本都显示为以下内容: 这是HTML 这是文本
它应该只显示文本或HTML,是什么导致了这种行为。
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,是什么导致了这种行为。