# Archiving all incoming/outgoing email



## xy16644 (Apr 12, 2011)

Currently I am running Postfix, SpamAssassin and Procmail to process/filter/deliver all my email. 

The one thing I would like to do is keep a copy of all incoming and outgoing emails. Basically I would like to create a daily archive of all emails.

Would this be done by a script or configured somewhere else?


----------



## aragon (Apr 12, 2011)

You mean for all accounts on your mail server?


----------



## xy16644 (Apr 12, 2011)

aragon said:
			
		

> You mean for all accounts on your mail server?



Yes, I want to archive/copy ALL incoming and outgoing email for ALL users.


----------



## aragon (Apr 12, 2011)

Have a look at Postfix's always_bcc option.


----------



## xy16644 (Apr 14, 2011)

Thanks aragon, I will have a play with this on the weekend and see how it goes.


----------



## xy16644 (Apr 16, 2011)

Thanks for that. I have enabled the always_bcc option but it doesn't seem to be behaving like I thought it would. In my /usr/local/etc/postfix/main.cf file I have added:

```
always_bcc = copyemail@domain.com
```

But when I send a test email from Gmail to my account (test@domain.com) theres TWO copies of the test email in the CopyEmail mailbox. When I looked in the /var/log/maillog it had some strange messages that weren't normally there:

```
Apr 16 15:49:51 alpha postfix/tlsmgr[35533]: warning: request to update table btree:/var/run/smtpd_tls_session_cache in non-postfix directory
 /var/run
Apr 16 15:49:51 alpha postfix/tlsmgr[35533]: warning: redirecting the request to postfix-owned data_directory /var/db/postfix
Apr 16 15:49:51 alpha postfix/smtpd[35531]: connect from mail-ww0-f44.google.com[74.125.82.44]
Apr 16 15:49:52 alpha postfix/smtpd[35531]: B0551216D7F: client=mail-ww0-f44.google.com[74.125.82.44]
Apr 16 15:49:52 alpha postfix/cleanup[35536]: B0551216D7F: message-id=<4DA9AC89.50002@gmail.com>
Apr 16 15:49:52 alpha postfix/qmgr[35526]: B0551216D7F: from=<testemail@gmail.com>, size=2128, nrcpt=2 (queue active)
Apr 16 15:49:52 alpha spamd[30860]: spamd: connection from localhost [127.0.0.1] at port 27612
Apr 16 15:49:53 alpha spamd[30860]: spamd: processing message <4DA9AC89.50002@gmail.com> for spamd:58
Apr 16 15:49:55 alpha spamd[30860]: spamd: clean message (-0.8/8.1) for spamd:58 in 2.1 seconds, 2122 bytes.
Apr 16 15:49:55 alpha spamd[30860]: spamd: result: . 0 -
 DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,TVD_SPACE_RATIO
 scantime=2.1,size=2122,user=spamd,uid=58,required_score=8.1,rhost=localhost,raddr=127.0.0.1,rport=27612,mid=
 <4DA9AC89.50002@gmail.com>,autolearn=ham
Apr 16 15:49:55 alpha postfix/pipe[35537]: B0551216D7F: to=<copyemail@domain.com>, relay=spamd, delay=2.5, delays=0.37/0.01/0/2.2, dsn=2.0.0,
 status=sent (delivered via spamd service)
Apr 16 15:49:55 alpha postfix/pipe[35537]: B0551216D7F: to=<test@domain.com>, relay=spamd, delay=2.5, delays=0.37/0.01/0/2.2, dsn=2.0.0,
 status=sent (delivered via spamd service)
Apr 16 15:49:55 alpha postfix/qmgr[35526]: B0551216D7F: removed
Apr 16 15:49:55 alpha postfix/pickup[35527]: 279CB216E63: uid=58 from=<testemail@gmail.com>
Apr 16 15:49:55 alpha postfix/cleanup[35536]: 279CB216E63: message-id=<4DA9AC89.50002@gmail.com>
Apr 16 15:49:55 alpha postfix/qmgr[35526]: 279CB216E63: from=<testemail@gmail.com>, size=2560, nrcpt=3 (queue active)
Apr 16 15:49:55 alpha spamd[30859]: prefork: child states: II
Apr 16 15:49:55 alpha postfix/local[35542]: 279CB216E63: to=<copyemail@domain.com>, relay=local, delay=2.3, delays=2.2/0.01/0/0.11, dsn=2.0.0,
 status=sent (delivered to command: /usr/local/bin/procmail)
Apr 16 15:49:55 alpha postfix/local[35543]: 279CB216E63: to=<xy16644@domain.com>, orig_to=<bob@domain.com>, relay=local, delay=2.3,
 delays=2.2/0.03/0/0.1, dsn=2.0.0, status=sent (delivered to command: /usr/local/bin/procmail)
Apr 16 15:49:55 alpha postfix/local[35545]: 279CB216E63: to=<copyemail@domain.com>, relay=local, delay=2.3, delays=2.2/0.05/0/0.09, dsn=2.0.0,
 status=sent (delivered to command: /usr/local/bin/procmail)
Apr 16 15:49:55 alpha postfix/qmgr[35526]: 279CB216E63: removed
Apr 16 15:50:23 alpha postfix/smtpd[35531]: disconnect from mail-ww0-f44.google.com[74.125.82.44]
```

What am I missing? Are there some more options that need setting for the always_bcc option? I know the account in the logs above has an alias email address (bob and xy16644) but even when I try to email an account with only one email address I still get two emails in the mailbox I have specified in the always_bcc options (copyemail@bsdpanic.com).


----------



## aragon (Apr 17, 2011)

I think the duplication might be due to your spamd setup.  When a message comes in, it gets bcc'd once and then delivered to your spamd service.  When spamd is done with the message, it delivers it back to Postfix, and this gets bcc'd again.

You probably need to add the option to master.cf instead, in such a way that always_bcc is only seen before spamd or only after it, not both.


----------



## klabacita (Apr 23, 2011)

I want to add something about bcc settings, I had been working with sender_ && recipient_ settings, this two options are monitoring one user, but that user had set up his mail client that always request "answer" when you open the email.

In my case I create 1 account called "audit at x. z" every time the user send a email this account return the "answer" email to this user.

 The point is, you want to enable this to all users, this catch my attention because if you have ten users that enable the option "user required your answer" just calculate how many emails the users will receive from the monitor account, they will call you about it.

This is my comment only, greetings


----------

