当我通过postfix发送电子邮件时,标题总是包含一个我想要删除的额外跃点。以下是标题:
From admin@mta.emailcab.com Sat Aug 20 18:40:58 2016
Return-Path: <admin@mta.emailcab.com>
X-Original-To: oneprovider@prosolutionmail.com
Delivered-To: oneprovider@prosolutionmail.com
Received: from mta.emailcab.com (mta.emailcab.com [52.58.223.55])
by prosolutionmail.com (Postfix) with ESMTP id 75F5B23C0AC7
for <oneprovider@prosolutionmail.com>; 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 header.i=@mta.emailcab.com
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 <oneprovider@prosolutionmail.com>; 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: admin@mta.emailcab.com
To: oneprovider@prosolutionmail.com
Message-Id: <20160820164058.0585383189@mta.emailcab.com>
Date: Sat, 20 Aug 2016 16:40:58 +0000 (UTC)
如您所见,有两个“已接收”标头,一个是传出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'] = "admin@example.com"
msgRoot['To'] = "foo@bar.com"
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("admin@example.com", "foo@bar.com", msgRoot.as_string())
答案 0 :(得分:0)
它不应该在python中修复,我不相信它无论如何都可以。 SMTP使用“寻址信封”(To:,From :)。你引用的Received From
值不是python问题,它是一个Postfix配置问题。想象它就像TCP一样,你没有看到封装/解封装会有什么不同,但它仍然会发生。当您查看原始邮件时,您将看到服务器与他们之间的SMTP通信。
您需要查看Postfix配置。
您的/etc/postfix/main.cf
中有一个值可以更改,但是......应该......更改您看到的值。
查找
myhostname = ???
我假设你的设置为localhost。
你在使用MySQL还是PostgreSQL?如果您在那里应该有users
和virtual_alias
表设置,myhostname
的值应该对应于表中的其中一个对象。
你能发布你的main.cf文件吗?
用户与您在同一台服务器上吗?