postfix: send a copy of every email to a given email address
Asked Answered
V

2

10

I have a postfix email server and there is an issue I want to debug. How can I configure it to send a copy of every email to my email (in addition to delivering the email to its intended recipients).

Vilhelmina answered 16/4, 2009 at 12:12 Comment(1)
serverfault.com/questions/407302/… has much better answer as it uses features provided by postfix.Dianemarie
A
14

Just add [email protected] in /etc/postfix/main.cf and restart postfix server. I've added this line in the bottom.

It really seems to be working. More about always_bcc here

Please don't forget to backup this file first.

Aldosterone answered 24/11, 2015 at 14:11 Comment(2)
Works like a charm. This should be the accepted answer!Krieg
Agree - best answerKemppe
S
10

I recently got this working, so though I'd share:

Sending all outgoing mail into Sent folders with postfix and cyrus imap.

Summary

Make postfix send bcc copies of all outgoing emails to a special "sent" mail account. Use sieve on this special account to redirect all emails to the Sent folder associated with the account.

  1. Create the email user account for sent

    The easiest way to do this is to create a new unix account for sent, setting the shell to /bin/false to prevent anyone from being able to log in:

    host$ sudo useradd sent
    host$ sudo chsh -s /bin/false sent
    
  2. Set up imap for the sent user

    Using cyradm we create a new mailbox (ie user) and give that user append access to all of our imap "Sent" folders:

    host$ $ cyradm -user cyrus localhost
    Password: <enter you cyrus user admin password here>
    localhost> createmailbox user.sent
    localhost> setaclmailbox user.%.Sent sent append
    Setting ACL on user.userx.Sent...OK.
    Setting ACL on user.usery.Sent...OK.
    . . .
    Setting ACL on user.userz.Sent...OK.
    localhost> exit
    
  3. Create a sieve script for the sent account

    This script will redirect all incoming email to the sent account, to the Sent folder in the senders Inbox.

    My script is called sent.sieve and looks something like this:

     # Sieve script for sent.  If outgoing email is bcc'ed to this account,
     # this sieve script will redirect it to the sender's Sent folder
     require ["fileinto"];
    
     if address :is :localpart "From" "userx" {
       fileinto "user.userx.Sent";
     }
     elsif address :is :localpart "From" "usery" {
       fileinto "user.usery.Sent";
     }
     elsif address :is :localpart "From" "userz" {
       fileinto "user.userz.Sent";
    }
    

    You will need to put in an entry for each of your users (userx, usery, userz in the example above). I have not been able to find a better way of doing this. Suggestions are welcomed to [email protected]

    Install the sieve script like this:

    host$ sieveshell localhost -user=sent -a=cyrus
    Password: <enter you cyrus user admin password here>
    > put sent.sieve
    > activate sent.sieve
    > quit
    
  4. Set up the bcc mapping for postfix

    In the postfix directory (/etc/postfix on debian) create a file called bcc_map that looks like this:

    # copy all locally sent mail to the sent account
    @yourdomain.com       [email protected]
    

    Compile this into a postfix hash file using:

    host$ sudo postmap bcc_map
    

    Add the following line to the postfix main.cf configuration file:

    sender_bcc_maps = hash:/etc/postfix/bcc_map
    

    And make postfix reload its configuration:

    host$ sudo /etc/init.d/postfix reload

  5. Test and Debug

    Send some email and check that it is copied into your Sent folder.

    In the event of problems you should check the cyrus and postfix logs (all logged to /var/log/syslog on my debian host). Typos and incorrect access permissions will usually result in some clue being sent to the logs.

Splenectomy answered 28/11, 2012 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.