发送smtp电子邮件,当我收到电子邮件时,它会显示纯文本版本和背靠背的html版本.这一点是从Sendgrid接收传入的电子邮件dicts,然后将它们发送给另一个用户.代码中引用的"message"对象是dict Sendgrid发布到我的端点.
这是我所看到的:
test
Me
Signature
test
Me
Signature
Run Code Online (Sandbox Code Playgroud)
这是我发送到mailServer的字符串:
Content-Type: multipart/mixed; boundary="===============5453410005537724489=="
MIME-Version: 1.0
To: me+test@domain.com
From: Me <me@domain.com>
Subject: test
reply-to: Original Sender <sender@theirdomain.com>
--===============5453410005537724489==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
test
Me
Signature
--===============5453410005537724489==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>test<br class=""><div apple-content-edited="true" class="">
<span>Me</span><br><span>Signature</span>
</div>
<br class=""></body></html>
--===============5453410005537724489==--
Run Code Online (Sandbox Code Playgroud)
最后,这是我用来发送电子邮件的Python:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
subject = …Run Code Online (Sandbox Code Playgroud)