-1

When I send emails through postfix, headers always contain one extra hop that I would like to get rid of. Here are the headers:

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)

As you can see, there are two "Received" headers, one of outgoing IP and a local one. How can I send the email so that only public ip will be visible?

The python code is something like that:

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())
offline15
  • 347
  • 3
  • 6
  • 14

1 Answers1

0

It shouldn't be fixed in python, I don't believe it can be anyway. SMTP uses the "addressed envelope"(To:,From:). The Received From value you are referencing isn't a python issue its a Postfix configuration issue., Think of it like TCP, you don't see the encapsulation/de-encapsulation which would be the difference, but it still occurs. When you view the raw message you are seeing the SMTP communication between your server and theirs.

You need to take a look at your Postfix config.

There is a value in your /etc/postfix/main.cf that you can change that will.. should... change that value you are seeing.

find:

myhostname = ???

I am assuming yours is set to localhost. Are you using MySQL or PostgreSQL? If you are there should be a users and a virtual_alias table setup, the value of myhostname should correspond to one of those objects in the table.

Could you post your main.cf file?

Are the users on the same server as you?

Leroy_Brown
  • 11
  • 1
  • 5
  • myhostname is mail.example.com. I was thinking if I can send the email with sendmail command from python. Like instead of connecting to local smtp, just run a process with sendmail command and a value of msgRoot.as_string() – offline15 Aug 22 '16 at 12:20
  • `sendmail` requires postfix – Leroy_Brown Aug 25 '16 at 16:52
  • sendmail -S test test@gmail.com sendmail: invalid option -- 'S' sendmail: fatal: open /etc/postfix/main.cf: No such file or directory – Leroy_Brown Sep 05 '16 at 11:04