【发布时间】:2018-05-31 15:11:48
【问题描述】:
当我使用 python sendmail.987654322@从 unix 服务器发送邮件时,我收到了如下所示的附加内容。
From nobody Mon Dec 18 09:36:01 2017 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit
我的代码如下。
#reading data from file
data = MIMEText(file('%s'%file_name).read())
#writing the content as html
content = MIMEText("<!DOCTYPE html><html><head><title></title></head><body>"+'%s'%data+"</body></html>", "html")
msg = MIMEMultipart("alternative")
msg["From"] = "sender@mail.com"
msg["To"] = "mymailid@mail.com"
msg["Subject"] = "python mail"
msg.attach(content)
p = Popen(["/usr/sbin/sendmail", "-t","-oi"], stdin=PIPE,universal_newlines=True)
p.communicate(msg.as_string())
【问题讨论】:
-
我只是想避免这种情况,警告。我的文件内容是一个 html 数据,但是当我收到邮件时,我在邮件上方看到了这个警告。我想禁用它。
-
我怀疑您还需要将
data明确标识为“html”。data = MIMEText(whatever, "html").
标签: python windows unix sendmail