Postfix | sender_bcc_maps for specific emails (with attach)

emailpostfix

How, if possible, copy all incoming mail with attachments to mybackup@example.net

If I use sender_bcc_map = type:table – all mails will be copied, without attachments too. I do not need that, I just need email with attachments.

My postfix version was 2.10.

Best Answer

Basically Postfix can detects whether an email has attachment or not by parsing the header. And for that, postfix has feature called header_checks and its variation. RFC 2183 section 2.2 defined that an attachment should be use Content-Dispostion: attachment; header. So, we can use mime_header_checks to detects an attachment then tell postfix to copy (BCC) it.

# main.cf
mime_header_checks = pcre:/etc/postfix/attachment_check

# /etc/postfix/attachment_check
/^Content-Disposition: attachment;/  BCC mybackup@example.net

Further info: Postfix BUILTIN_FILTER_README and Filter mail attachments


How, if possible, copy all incoming mail with attachments to mybackup@example.net

FYI, Postfix doesn't have concept incoming and outgoing email. All email passed through postfix was considered coming from other client and postfix relay it, to other mailserver, LMTP server, mailbox and others. So I'm afraid that this method will affect your emails, both incoming and outgoing (with some exception below).

If your outgoing email source was sendmail (mail command) or submitted via submission (587) or submitted through IP Address 127.0.0.1, you can selectively turn off the header_checks. Specify this configuration in master.cf

# By default turn on header_checks
smtp                inet  n     -     n     -     -   smtpd
# Disable header_checks on loopback IP address 
127.0.0.1:smtp      inet  n     -     n     -     -   smtpd
   -o receive_override_options=no_header_body_checks
# Disable header_checks when email enter via sendmail/mail command
pickup              fifo  n     -     n    60     1   pickup
   -o receive_override_options=no_header_body_checks
# Disable header_checks on submission port
submission          inet  n     -     n     -     -   smtpd
   -o receive_override_options=no_header_body_checks

Source: Turning Off Body & Header Checks for Internal Users

Related Topic