2016-08-21 89 views
-1

当我通过postfix发送邮件时,邮件总是包含一个额外的跳跃,我想摆脱。这里是标题:使用python通过postfix发送邮件

From [email protected] Sat Aug 20 18:40:58 2016 
Return-Path: <[email protected]> 
X-Original-To: [email protected] 
Delivered-To: [email protected] 
Received: from mta.emailcab.com (mta.emailcab.com [52.58.223.55]) 
    by prosolutionmail.com (Postfix) with ESMTP id 75F5B23C0AC7 
    for <[email protected]>; Sat, 20 Aug 2016 18:40:58 +0200 (CEST) 
Authentication-Results: prosolutionmail.com; dkim=pass 
    reason="2048-bit key; unprotected key" 
    header.d=mta.emailcab.com [email protected] 
    header.b=mXAsVoW+; dkim-adsp=pass; dkim-atps=neutral 
Received: from [127.0.0.1] (localhost [127.0.0.1]) 
    by mta.emailcab.com (Postfix) with ESMTP id 0585383189 
    for <[email protected]>; Sat, 20 Aug 2016 16:40:58 +0000 (UTC) 
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mta.emailcab.com; 
    s=key1; t=1471711258; 
    bh=BUn1x+fCFHl9Q+e98U5epKcL5xZNNNU3Lq/zNz0IMnI=; 
    h=Subject:From:To:Date:From; 
    b=mXAsVoW+IYePOdDe1d7OyQdYpRzNoKdYclLEv/wXm3dDjJulDMfr5HM274U1ypNNs 
    OCqK5TNRo4UMrFqIcU38BVjOIwN3gPOStxs3jSEmoWLXynIAuclbNew692P2KY7jkn 
    oU7lhPZ1CwBln+qEKKXbyuiXtRmbA2Qp1pvLu+R9T/WfPzWiVhe+2CPq9ob3j3mwBW 
    oBjLNvmbm74eenMKxv8G47FBi7HS4+9eSuUI9TVV0fb/qZwNHwumpFeTA5DPRzkQPM 
    u5imAbdz5GqXxs4wo4UXTpWEb7dSkzJu7/2ebLshCnnuSoN8HV5j79GEoidyzmqEpC 
    saF1XA+rJvKwg== 
Content-Type: multipart/alternative; boundary="===============5118095836845773678==" 
MIME-Version: 1.0 
Subject: =?utf-8?b?0JrQsNC6INC00L7QsdGA0LDRgtGM0YHRjyDQtNC+INCb0YzQstC+0LLQsD8=?= 
From: [email protected] 
To: [email protected] 
Message-Id: <[email protected]> 
Date: Sat, 20 Aug 2016 16:40:58 +0000 (UTC) 

正如你所看到的,有两个“Received”标头,一个外向IP和一个本地标头。我如何发送电子邮件,以便只有公共IP可见?

的Python代码是类似的东西:

import smtplib 

from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText 
from email.mime.image import MIMEImage 
from email.header import Header 

smtp = smtplib.SMTP() 
smtp.connect('localhost') 

msgRoot = MIMEMultipart("alternative") 
msgRoot['Subject'] = Header("Subject subject", "utf-8") 
msgRoot['From'] = "[email protected]" 
msgRoot['To'] = "[email protected]" 
text = MIMEText(open('template.txt', 'r').read(), "plain", "utf-8") 
msgRoot.attach(text) 
html = MIMEText(open('template.html', 'r').read(), "html", "utf-8") 
msgRoot.attach(html) 
smtp.sendmail("[email protected]", "[email protected]", msgRoot.as_string()) 

回答

0

它不应该被固定在python,我不相信它可以是无妨。 SMTP使用“地址信封”(To:,From :)。你引用的Received From的值不是python问题,它是Postfix的配置问题。想象它像TCP,你没有看到封装/解封装,这将是不同的,但它仍然会发生。当您查看原始消息时,您会看到服务器和他们的服务器之间的SMTP通信。

你需要看看你的Postfix配置。

您的/etc/postfix/main.cf中存在一个值,您可以更改该值,应该...更改您所看到的值。

发现:

myhostname = ??? 

我假设你设置为localhost。 你使用的是MySQL还是PostgreSQL?如果你在那里应该有一个users和一个​​表设置,myhostname的值应该对应于表中的那些对象之一。

你能发布你的main.cf文件吗?

与您在同一台服务器上的用户是?

+0

myhostname是mail.example.com。我在想如果我可以用python的sendmail命令发送邮件。像不是连接到本地smtp,而是运行一个sendmail命令并且值为msgRoot.as_string()的进程 – offline15

+0

'sendmail'需要postfix –

+0

sendmail -S test [email protected] sendmail:无效选项 - 'S' sendmail:fatal:打开/etc/postfix/main.cf:没有这样的文件或目录 –