0

I am trying to send email back to the sender using sendmail -oi -t, but somehow it extracted MTA, how to write the receipt to get the real sender since the email return-path and first From in the email header is MTA, not the real sender? So sendmail can deliver email back to: Sender: +xxxxxxxxxx@tmomail.net or From: +xxxxxxxxxx@tmomail.net

Here is the procmail.log and email received:

...
procmail: Matched "+1xxxxxxxxxx@tmomail.net"
procmail: Match on "^Sender: \/.+"
procmail: Assigning "LASTFOLDER= (/usr/bin/formail -rA"Precedence: junk" \
-A"X-Loop:addr@mydomain.com" \
-I"To: $MATCH"; \
echo "$result"; \
) | /usr/sbin/sendmail -oi -t"
procmail: Assigning "PATH=/home/r/bin:/usr/local/bin:/usr/bin:/bin"
procmail: Unable to treat as directory "/var/mail/new"
procmail: Skipped "/var/mail"
procmail: Assigning "LASTFOLDER=/var/mail/r"
procmail: Executing " (/usr/bin/formail -rA"Precedence: junk" \
-A"X-Loop:addr2mydomain.com" \
-I"To: $MATCH"; \
echo "$result"; \
) | /usr/sbin/sendmail -oi -t"
procmail: Opening "/var/mail/r"
procmail: Acquiring kernel-lock
procmail: Notified comsat: "r@884017:/var/mail/r"
From btv1==909280b6006==+1xxxxxxxxxx/TYPE=PLMN@tmomail.net  Mon Apr 11  17:09:24 2016
Folder: /var/mail/r             

Here is the email header:

From btv1==9062f44d095==+xxxxxxxxxx/TYPE=PLMN@tmomail.net  Fri Apr  8 00:19:01 2016
Return-Path: <btv1==9062f44d095==+xxxxxxxxxx/TYPE=PLMN@tmomail.net>
X-Original-To: recipient@mydomain.com
Delivered-To: recipient@mydomain.com
Received: from ch3p-tmo-mm3-sfw004.syniverse.com (chi-tmo-mm3.syniverse.com   [x.x.x.x])
    by mail.mydomain.com (Postfix) with ESMTP id 7D444222D0
    for <recipient@mydomain.com>; Fri,  8 Apr 2016 00:19:01 +0000 (UTC)
Received: from tmobile.net ([10.166.3.161]) by ch3p-tmo-mm3-      sfw004.syniverse.com with ESMTP id RuIW8dEKbs9H2Iyg for <r@mr4.biz>; Fri, 08 Apr   2016 00:18:58 +0000 (GMT)
To: recipient@mydomain.com
From: +xxxxxxxxxx@tmomail.net
Content-Type: multipart/related;Type="text/html";boundary="-boundaryRMS123"
Date: Fri, 8 Apr 2016 00:18:58 GMT
Message-ID: 20160308001858639184@mavenir.com
Sender: +xxxxxxxxxx@tmomail.net
User-Agent: iPhoneOS/9.2.1 (13D15)
X-Virus-Scanned: by bsmtpd at syniverse.com

Here is the last part of recipe:

:0hc
* !^X-Loop:old@domain.com
* ^Sender: \/.+
| (/usr/bin/formail -rA"Precedence: junk" \
                     -A"X-Loop:addr@mydomain.com" ; \
   echo "$result"; \
) | /usr/sbin/sendmail -oi -t
Ann W.
  • 27
  • 1
  • 7

1 Answers1

1

You are instructing formail to generate a reply and it will faithfully attempt to do so. By default, the -r option tries to select the best one out of a priority list of headers1; if the message has a Reply-To: header (but no Resent-From:, and no Resent-Reply-To:, etc), it will generate a reply to that.

With -rt, you get RFC-compliant but somewhat less pragmatic behavior, but it doesn't really help here.

Anyway, if you know exactly which header you want to reply to, just use that.

:0hc
* ! ^X-Loop:old@domain\.com
* ^Sender: \/.+
| ( formail -rA"Precedence: junk" \
             -A"X-Loop:r@mydomain.com" \
             -I"To: $MATCH"; \
    echo "$result"; \
  ) | /usr/sbin/sendmail -oi -t

This uses formail -r in order to get correct In-reply-to: and References: headers (as well as any previous X-Loop:) but overwrites the generated To: header with the one we captured from the Sender: header.

The \/ token in a Procmail regular expression causes anything after it to be captured into the variable MATCH. We use this to grab the value of the Sender: header from the incoming message.


  1. http://www.iki.fi/era/procmail/formail.html -- this is from an older version, but this code hasn't changed in a loooooong time.
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • I added the line * ^Sender: \/.+ and -I"To: $MATCH"; \, it says: procmail: Executing " (/usr/bin/formail -rA"Precedence: junk" \ -A"X-Loop:addr@mydomain.com" ; \ -I"To: $MATCH"; \ " /bin/sh: 3: Syntax error: end of file unexpected (expecting ")") – Ann W. Apr 11 '16 at 06:13
  • What line * ^Sender: \/.+ does and the $MATCH is the sender? Why it's inside the double quote? – Ann W. Apr 11 '16 at 06:14
  • The `\/` token in a Procmail regular expression causes anything after it to be captured into the variable `MATCH`. We generally put double quotes around all variables unless we specifically require the shell to perform token splitting and wildcard expansion on the value; see http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable – tripleee Apr 11 '16 at 06:18
  • The error message looks like maybe you have whitespace after one of the backslashes. They need to be the very last thing on the line; their purpose is to escape the following newline. Also, the semicolon after `-A"XLoop:..."` needs to be removed. – tripleee Apr 11 '16 at 06:20
  • Thanks! it takes longer to email back, don't know why @tripleee – Ann W. Apr 11 '16 at 17:20
  • What takes longer, how exactly? – tripleee Apr 11 '16 at 18:39