我在 Postfix 中有一个电子邮件虚拟别名,可以将电子邮件转发到另一个地址:[电子邮件保护]->[电子邮件保护]。 这域名2.com是一个解析电子邮件并将其发送到脚本的万能工具。在脚本中,我可以访问电子邮件标头,在那里我可以看到标头。我还想知道最终收件人是谁,在本例中。您知道有什么方法可以将其添加为自定义标头吗?谢谢To: <[email protected]>
[email protected]
更新:
我使用的是 Centos 7 和 Virtualmin。这是我的postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
allow_percent_hack = no
authorized_submit_users = root
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailbox_size_limit = 0
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost, domain1
myhostname = mail.domain1.com
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
recipient_canonical_classes = envelope_recipient
recipient_canonical_maps = tcp:127.0.0.1:10002
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sender_bcc_maps = hash:/etc/postfix/bcc
sender_canonical_classes = envelope_sender
sender_canonical_maps = tcp:127.0.0.1:10001
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
我目前收到的标头[电子邮件保护]是:
X-Envelope-To: <[email protected]>
Received: from mail-qk0-f170.google.com (mail-qk0-f170.google.com [209.85.220.170]) by mail.domain1.com (Postfix) with ESMTP id DD6A419EAE for <[email protected]>; Mon, 14 Mar 2016 14:26:50 +0000 (UTC)
Received: by mail-qk0-f170.google.com with SMTP id s68so75293658qkh.3 for <[email protected]>; Mon, 14 Mar 2016 07:26:50 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sender1-com.20150623.gappssmtp.com; s=20150623; h=date:subject:from:message-id:mime-version:to; bh=hqH2fYTPM8TH6JmNeCLDMgOPLarFPGZIH9iNM2C8si8=; b=QLx2ne7ecBDzFf7KxvphGmJ3j2ofGv2hPsnDQc/2WGaIsXkrNUactEHg06dHvUx7Fr A6sfsY3ldQeFYctYkaFkHmIIahOA5wU+//vQt63eezyT7DwPPgdV3M325hrRIl/yXtzx /a9i6o9HodPKLO9mzw3O/BFrkhX2/yns8+L4m6flxh7pO6XR/L+7CA52q6tikj3LA0vY I6EVUjALjGESkVvfLQCqz0xqihrydx5ZjHQs8/kejPyHNKjuG1mhT71Aw8fOpm5cr/U4 oFtg8D8mk04KSNCJpPfj4r8q6PWkk2lWmrMZBqVb1lgsc++Ms94OnTUOP66ahkF4FSHe hk0Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:subject:from:message-id:mime-version:to; bh=hqH2fYTPM8TH6JmNeCLDMgOPLarFPGZIH9iNM2C8si8=; b=C+MBNHvzJgDJytvU0O77IMci0KDVbBAoE7vjh1l7ywehwO8rbts8g1Aw1rLKqVRC1j 7AuSSNl4Aw24EHrKJ/d0FeeZj7wYttzieAGcoVHO/aU8nU1VB4z1551/JNLdERT12JsJ Q9vi8wSdn/YyywVcQrYAkj2AbJJuVDxAWwnh+DFKMtfSqhSjLouXIgHW3Em/n6HKk/Fo gQ3YX3VcbVhh/Wb1bnhYKa9p+dHycxR/6FqH6iUPfC9FOoyQgyT5Dy22uf14qc+4BfxL aI7zkWZSnrTGvAo0qZYv83Ju9y/OqnIzu+8rtcvvFTMBlfbSRZk7EPHoK6epOvk2gGCr YdUg==
X-Gm-Message-State: AD7BkJJN9qbPo6gcrUH1cqYbdbf1ONXUw66KBuM1smFgz/9/kg7LqgsyGfGxkI5riSw59A==
X-Received: by 10.55.20.224 with SMTP id 93mr31121731qku.109.1457965610167; Mon, 14 Mar 2016 07:26:50 -0700 (PDT)
Received: from localhost (ec2-52-90-4-238.compute-1.amazonaws.com. [52.90.4.238]) by smtp.gmail.com with ESMTPSA id x64sm9199694qhx.47.2016.03.14.07.26.49 for <[email protected]> (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Mar 2016 07:26:49 -0700 (PDT)
Date: Mon, 14 Mar 2016 07:26:40 -0700
X-Mailer: Polymail
Subject: test
From: Jesús Carrera <[email protected]>
X-Polymail-Id: 56e6c9f42bcdb00a00000023
Message-ID: <[email protected]>
Mime-Version: 1.0
To: <[email protected]>
答案1
我不关心邮件头的名称,只想知道如何将最后一个收件人添加到邮件头中。该怎么做?
正如我之前所说 - 你可以使用X-原始-至/到标头。
基本测试
# echo "Hello world" | swaks -4 --server localhost:25 --from [email protected] --to [email protected] --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:<[email protected]>
<- 250 2.1.0 Ok
-> RCPT TO:<[email protected]>
<- 250 2.1.5 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> Date: Tue, 15 Mar 2016 09:34:18 +0000
-> To: [email protected]
-> From: [email protected]
-> 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.
检查邮件日志
# 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=<[email protected]>
Mar 15 09:34:18 ci postfix/qmgr[24553]: 8F6CE1C0B33: from=<[email protected]>, size=428, nrcpt=1 (queue active)
Mar 15 09:34:18 ci postfix/smtp[24560]: 8F6CE1C0B33: to=<[email protected]>, orig_to=<[email protected]>, 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
如您所见,电子邮件最初发送至[电子邮件保护]
orig_to=<[email protected]>
但被送到[电子邮件保护]通过中继 smtp.example.com[192.168.88.230]:25
to=<[email protected]>
来自中继的邮件日志
# 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=<[email protected]>
Mar 15 06:38:07 relay postfix/qmgr[19244]: 292366065D: from=<[email protected]>, size=622, nrcpt=1 (queue active)
Mar 15 06:38:07 relay postfix/virtual[19249]: 292366065D: to=<[email protected]>, 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
电子邮件本身
# cat /var/mail/virtual/example.com/alex
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from smtp.example.net (smtp.example.net [192.168.88.87])
by smtp.example.com (Postfix) with ESMTP id 292366065D
for <[email protected]>; 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 <[email protected]>; Tue, 15 Mar 2016 09:38:10 +0000 (UTC)
Date: Tue, 15 Mar 2016 09:38:10 +0000
To: [email protected]
From: [email protected]
Subject: Test message
X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
Message-Id: <[email protected]>
Hello world
如你看到的
- [X-Original-To]:将包含最终收件人
- [收件人]:将包含原始收件人
但我不知道该怎么做
您可以尝试的最后一件事是通过 header_checks 选项添加标头。您应该在“中继”服务器上添加以下选项
# main.cf
header_checks = pcre:/etc/postfix/add_original_rcpt.pcre
# cat add_original_rcpt.pcre
/^To:(\s)?(.*)$/ PREPEND X-Original-To: $2