Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sendmail,错误_Python_Windows_Unix_Sendmail - Fatal编程技术网

Python sendmail,错误

Python sendmail,错误,python,windows,unix,sendmail,Python,Windows,Unix,Sendmail,当我使用pythonsendmail从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('

当我使用python
sendmail从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())
#从文件中读取数据
data=MIMEText(文件(“%s”%file\u name).read())
#将内容编写为html
content=MIMEText(“+'%s'%data+”,“html”)
msg=MIMEMultipart(“备选方案”)
消息[“来自”]=“sender@mail.com"
消息[“至”]=“mymailid@mail.com"
msg[“主题”]=“python邮件”
msg.attach(内容)
p=Popen([“/usr/sbin/sendmail”、“-t”、“-oi”],stdin=PIPE,universal\u newlines=True)
p、 通信(msg.as_string())

您正在将电子邮件内容分为两部分,即
数据
内容
。您需要明确确认两者都是HTML。所以改变

data = MIMEText(file('%s'%file_name).read())


您将电子邮件内容分为两部分,即
数据
内容
。您需要明确确认两者都是HTML。所以改变

data = MIMEText(file('%s'%file_name).read())


您应该查看消息字符串。您看到的消息不是警告,它只是您在消息中写入的内容:

data = MIMEText(file('%s'%file_name).read())
content = MIMEText("<!DOCTYPE html><html><head><title></title></head><body>"
    +'%s'%data+"</body></html>", "html")
但我也认为,您不需要将其包含到另一个级别,使用
MIMEMultipart(“可选”)
msg=content
可能就足够了

最后,当标准库aloready中的
smtplib
模块知道如何发送消息时,我并不认为明确启动一个新进程来执行sendmail真的是过火了:

import smtplib

server = smtplib.SMTP()
server.send_message(msg)
server.quit()

您应该查看消息字符串。您看到的消息不是警告,它只是您在消息中写入的内容:

data = MIMEText(file('%s'%file_name).read())
content = MIMEText("<!DOCTYPE html><html><head><title></title></head><body>"
    +'%s'%data+"</body></html>", "html")
但我也认为,您不需要将其包含到另一个级别,使用
MIMEMultipart(“可选”)
msg=content
可能就足够了

最后,当标准库aloready中的
smtplib
模块知道如何发送消息时,我并不认为明确启动一个新进程来执行sendmail真的是过火了:

import smtplib

server = smtplib.SMTP()
server.send_message(msg)
server.quit()

我只是想避免,警告。我的文件内容是html数据,但当我收到邮件时,我在邮件上方看到此警告。我想禁用它。我怀疑您还需要明确地将
数据
标识为“html”
data=MIMEText(随便什么,“html”)
。我只是想避免可能的重复,警告。我的文件内容是html数据,但当我收到邮件时,我在邮件上方看到此警告。我想禁用它。我怀疑您还需要明确地将
数据
标识为“html”
data=MIMEText(不管什么,“html”)
。可能是重复的谢谢,实际上我的错误是,我在数据中添加了多个html头,步骤:
content=MIMEText(“++'%s'%data+”,“html”)
不是必需的,只是以html的形式读取文件内容就可以了。谢谢,实际上我的错误是,我已经向数据中添加了多个HTML头,步骤:
content=MIMEText(“++'%s'%data+”,“HTML”)
不是必需的,只需将文件内容读取为HTML即可。谢谢,实际上我的错误是,我向数据中添加了多个HTML头,步骤:
content=MIMEText(“++'%s data+”,“HTML”)
没有必要,只需将文件内容作为HTML读取即可。谢谢,实际上我的错误是,我已将多个HTML标题添加到数据中,步骤:
content=MIMEText(“+”'%s'%data+”,“HTML”)
没有必要,只需将文件内容作为HTML读取即可。