I don't care about the name of the header, just want to know how to add the last recipient to the headers. How to do that?
As I said before - you can use X-Original-To/To headers.
Basic test
# echo "Hello world" | swaks -4 --server localhost:25 --from alex.hha@gmail.com --to alex@example.net --h-Subject "Test message" --body -
=== Trying localhost:25...
=== Connected to localhost.
<- 220 smtp.example.net ESMTP Postfix
-> EHLO jenkins.example.net
<- 250-smtp.example.net
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-VRFY
<- 250-ETRN
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250 DSN
-> MAIL FROM:<alex.hha@gmail.com>
<- 250 2.1.0 Ok
-> RCPT TO:<alex@example.net>
<- 250 2.1.5 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> Date: Tue, 15 Mar 2016 09:34:18 +0000
-> To: alex@example.net
-> From: alex.hha@gmail.com
-> Subject: Test message
-> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
->
-> Hello world
->
->
-> .
<- 250 2.0.0 Ok: queued as 8F6CE1C0B33
-> QUIT
<- 221 2.0.0 Bye
=== Connection closed with remote host.
Check maillog
# grep 8F6CE1C0B33 /var/log/maillog
Mar 15 09:34:18 ci postfix/smtpd[24556]: 8F6CE1C0B33: client=localhost[127.0.0.1]
Mar 15 09:34:18 ci postfix/cleanup[24559]: 8F6CE1C0B33: message-id=<20160315093418.8F6CE1C0B33@smtp.example.net>
Mar 15 09:34:18 ci postfix/qmgr[24553]: 8F6CE1C0B33: from=<alex.hha@gmail.com>, size=428, nrcpt=1 (queue active)
Mar 15 09:34:18 ci postfix/smtp[24560]: 8F6CE1C0B33: to=<alex@example.com>, orig_to=<alex@example.net>, relay=smtp.example.com[192.168.88.230]:25, delay=0.06, delays=0.02/0.01/0.01/0.03, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as BFFDA6065D)
Mar 15 09:34:18 ci postfix/qmgr[24553]: 8F6CE1C0B33: removed
As you can see originally the email was sent to alex@example.net
orig_to=<alex@example.net>
but was delivered to alex@example.com via relay smtp.example.com[192.168.88.230]:25
to=<alex@example.com>
Maillog from the relay
# grep 292366065D /var/log/maillog
Mar 15 06:38:07 relay postfix/smtpd[19245]: 292366065D: client=smtp.example.net[192.168.88.87]
Mar 15 06:38:07 relay postfix/cleanup[19248]: 292366065D: message-id=<20160315093810.E71EA1C0B33@smtp.example.net>
Mar 15 06:38:07 relay postfix/qmgr[19244]: 292366065D: from=<alex.hha@gmail.com>, size=622, nrcpt=1 (queue active)
Mar 15 06:38:07 relay postfix/virtual[19249]: 292366065D: to=<alex@example.com>, relay=virtual, delay=0.03, delays=0.02/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Mar 15 06:38:07 relay postfix/qmgr[19244]: 292366065D: removed
The email itself
# cat /var/mail/virtual/example.com/alex
Return-Path: <alex.hha@gmail.com>
X-Original-To: alex@example.com
Delivered-To: alex@example.com
Received: from smtp.example.net (smtp.example.net [192.168.88.87])
by smtp.example.com (Postfix) with ESMTP id 292366065D
for <alex@example.com>; Tue, 15 Mar 2016 06:38:07 -0400 (EDT)
Received: from jenkins.example.net (localhost [127.0.0.1])
by smtp.example.net (Postfix) with ESMTP id E71EA1C0B33
for <alex@example.net>; Tue, 15 Mar 2016 09:38:10 +0000 (UTC)
Date: Tue, 15 Mar 2016 09:38:10 +0000
To: alex@example.net
From: alex.hha@gmail.com
Subject: Test message
X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
Message-Id: <20160315093810.E71EA1C0B33@smtp.example.net>
Hello world
As you can see
- [X-Original-To]: will contain final recipient
- [To]: will contain original
recipient
but I don't know how to do it
The last thing you can try - is to add header via header_checks option. You should add the following option on the "relay" server
# main.cf
header_checks = pcre:/etc/postfix/add_original_rcpt.pcre
# cat add_original_rcpt.pcre
/^To:(\s)?(.*)$/ PREPEND X-Original-To: $2
Best Answer
Since you're running Ubuntu, you should be able to get a functional postfix setup by running
This should run a dialog that asks you a series of questions. One of the questions will be along the lines of "Other destinations to accept mail for", to which you should reply with an empty string (i.e. blank). You should also be certain to give a valid email address (e.g. yours) in answer to the question "Root and postmaster mail recipient", so that mail generated by the system by/for system users gets delivered somewhere.