Postfix BCC

最後更新: 2021-09-13

前言

查表的次序:

  • [email protected]
  • [email protected]
    ----
  • user+extension       <-- 當 $myorigin, $mydestination 成立時
  • user                       <-- 當 $myorigin, $mydestination 成立時
    ----
  • domain.tld

Note: if mail to the BCC address bounces it will be returned to the sender.

目錄

  • BCC By DB
  • always_bcc
  • 解決 bcc 只有一個收件者問題
  • 某個 smtpd 不用 bcc
  • 簡易 File Base BCC 設定
  • 某些 mailbox 不用被 BCC

 


BCC By DB

 

設定

  • sender_bcc_maps          # Indexed by sender address
  • recipient_bcc_maps       # Indexed by recipient address

main.cf

proxy_read_maps = ... $recipient_bcc_maps $sender_bcc_maps

# bcc settings
recipient_bcc_maps =
    proxy:mysql:/etc/postfix/mysql-recipient_bcc_maps_user.cf
    proxy:mysql:/etc/postfix/mysql-recipient_bcc_maps_domain.cf
sender_bcc_maps =
    proxy:mysql:/etc/postfix/mysql-sender_bcc_maps_user.cf
    proxy:mysql:/etc/postfix/mysql-sender_bcc_maps_domain.cf

Notes:

 * multiple results are not supported

 * 當 always_bcc 及 ?_bcc_maps 同時存在時, 那兩邊都會生效

 * Postfix 2.3 and later the BCC address is added as if it was specified with NOTIFY=NONE.
    (The sender will not be notified when the BCC address is undeliverable)

 * To avoid mailer loops, automatic BCC recipients are not generated after Postfix forwards mail internally,
    or after Postfix generates mail itself.

 * 如果某 mail 同時中了 recipient_bcc_maps 及 sender_bcc_maps,
    (e.g. mail_to = mail_from = datahunter.org)
    而它們的 bcc_to 一樣時, 那 bcc_to 只會收到 1 個 mail

i.e. mysql-recipient_bcc_maps_user

touch mysql-recipient_bcc_maps_user

chmod 640 mysql-recipient_bcc_maps_user

chgrp postfix mysql-recipient_bcc_maps_user

user        = bccadmin
password    = YOUR_PW
hosts       = 127.0.0.1
port        = 3306
dbname      = dbispconfig
query       = SELECT bcc_to FROM mail_recipient_bcc
                WHERE mail_to='%s' AND active=1

DB schema:

CREATE TABLE IF NOT EXISTS `mail_recipient_bcc` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `mail_to` varchar(255) NOT NULL,
  `bcc_to` varchar(255) NOT NULL DEFAULT 'postmaster@localhost',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `remark` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY (`mail_to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

建立 record

INSERT INTO `mail_sender_bcc` (`mail_to`, `bcc_to`, `active`)
    VALUES ('[email protected]', '[email protected]', 1);

 


always_bcc

 

"blind carbon copy" of each message (In/Out) that is received by the Postfix mail system.

main.cf

always_bcc = [email protected]

 


解決 bcc 只有一個收件者問題

 

You can not specify multiple recipients in the right hand side of the "recipient_bcc_maps" !!

main.cf:

always_bcc = always_bcc_list

/etc/aliases:

always_bcc_list: [email protected], [email protected]

 


某個 smtpd 不用 bcc

 

"-o" 唔 work

2525 inet n       -       n       -       -       smtpd
  -o smtpd_enforce_tls=no
  -o smtpd_sasl_auth_enable=yes
  -o always_bcc=
  -o sender_bcc_maps=
  -o recipient_bcc_maps=
  -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject

原因:

always_bcc is not an smtpd(8)feature, 它是由 cleanup 負責的

解決:

127.0.0.1:2525 inet n - n - 10  smtpd
    -o content_filter=
    -o smtpd_enforce_tls=no
    -o smtpd_sasl_auth_enable=yes
    -o cleanup_service_name=altbcc
    -o syslog_name=postfix/altbcc
    -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject

altbcc   unix  n       -       n       -       0       cleanup
    -o always_bcc=
    -o sender_bcc_maps=
    -o recipient_bcc_maps=

$config_directory/alt_rcpt_bcc contains your BCC mappings,

  and a transport(5) mapping directs the appropriate mail to this special smtpd.

 


簡易 File Base BCC 設定

 

main.cf

sender_bcc_maps = hash:/etc/postfix/sender_bcc_maps.cf
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc_maps.cf

# 設定

echo "bcc_user@domain copyto@domain" >> /etc/postfix/sender_bcc_maps.cf

echo "bcc_user@domain copyto@domain" >> /etc/postfix/recipient_bcc_maps.cf

# 建立 map

postmap /etc/postfix/sender_bcc_maps.cf

postmap /etc/postfix/recipient_bcc_maps.cf
 

 


 

Creative Commons license icon Creative Commons license icon