I'm trying to configure Postfix (on a RHEL 6.5) to modify the content of incoming messages and forward the emails to a remote server. I used a Perl script piped to Postfix to modify the content, and the emails get injected back into Postfix using Sendmail.
When the email first comes to the server, I see the from
field being initialized correctly, but then it gets rewritten:
postfix/smtpd[29150]: connect from ** local domain **[x.x.x.x]
postfix/smtpd[29150]: 2CF665F6B9: client=** local domain **[x.x.x.x]
postfix/cleanup[29155]: 2CF665F6B9: message-id=<msg_172345>
postfix/qmgr[29120]: 2CF665F6B9: from=<original_sender@external.domain>, size=66895, nrcpt=1 (queue active)
postfix/pickup[29119]: 472C75F6BC: uid=600 from=<admin>
postfix/cleanup[29155]: 472C75F6BC: message-id=<msg_172345>
postfix/pipe[29159]: 2CF665F6B9: to=<correct_recipient@external.domain>, relay=myhook, delay=3.1, delays=3/0.01/0/0.06, dsn=2.0.0, status=sent (delivered via myhook service)
postfix/qmgr[29120]: 2CF665F6B9: removed
postfix/qmgr[29120]: 472C75F6BC: from=<admin@** local domain **>, size=67025, nrcpt=1 (queue active)
As you can see, the from
field changes from original_sender@external.domain
to admin@** local domain **
I assume that admin
comes from the pipe user=admin
in the main.cf, and the local domain is taken from /etc/hosts
.
What I need here is to keep the original sender of the email, but it seems I'm not able to achieve that. Could you point me in the right direction?
Thank you so much.
EDIT:
This is my Postfix configuration:
postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_checks = regexp:/etc/postfix/header_checks
html_directory = no
inet_interfaces = $myhostname, localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
myhostname = ** local domain **
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_connection_cache_on_demand = yes
smtpd_helo_required = no
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
It seems that my Postfix doesn't accept the -M
flag.
This is the master.cf:
# cat /etc/postfix/master.cf | grep -v "#"
smtp inet n - n - - smtpd
-o content_filter=myhook:
pickup fifo n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
-o smtp_fallback_relay=
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
myhook unix - n n - - pipe
flags=Rq user=admin argv=/var/tmp/filter.pl ${sender} ${recipient}