Linux sendmail中文乱码

时间:2019-11-19 08:48:43

标签: python linux sendmail

当我在python中使用sendmail发送一些中文(从txt)时,它将在Email中出现乱码, 但是使用smtp发送,这是正常的(真中文)。

def sendMail():
    filea= '/home/labs/temp/news.txt'
    with open(filea, 'r') as f:
        ne = f.read()
    # fileb='/home/labs/temp/send1.txt'    
    # with open(fileb, 'w',encoding='utf-8') as f:     
    #     news_info_str=','.join(news_info)
    #     f.write(news_info_str)
    sendmail_location = "/usr/sbin/sendmail" # sendmail location
    p = os.popen("%s -t" % sendmail_location, "w")
    p.write("From: %s\n" % "no-reply@redhat.com")
    p.write("To: %s\n" % "xxx@redhat.com")
    p.write("Subject: thesubject\n")
    p.write("\n") # blank line separating headers from body
    p.write(ne)
    status = p.close()
    print('fin')

0 个答案:

没有答案