Sunday, November 30, 2008

Postfix + BCC

BCC option available with Postfix which are very useful to get copies of incoming/outgoing emails of users without their knowledge.

Case 1:

A copy of all user's incoming and outgoing emails should automatically bcc'ed to a specific user without any user's attention.

Add always_bcc in /etc/postfix/main.cf file.

always_bcc = archiveuser@domain.com

Reload the Postfix config.
/etc/init.d/postfix reload

Case 2:

All incoming emails for suspecioususer@domain.com should be bcc'ed to a manager.

Add following in /etc/postfix/main.cf file.

recipient_bcc_maps = hash:/etc/postfix/recipient_bcc

Create a file /etc/postfix/recipient_bcc and enter userlist whose incoming emails you want to bcc to another user.

cat /etc/postfix/recipient_bcc
suspecioususer@domain.com manager@domain.com
otheruser@domain.com otheruser@domain.com

Create the hash file.
postmap /etc/postfix/recipient_bcc

Reload the Postfix config.
/etc/init.d/postfix reload

Check /var/log/maillog for results.

You can use sender_maps in main.cf which will send all outgoing emails of a specific user to other user mentioned in maps file. The configuration will look almost similar as mentioned above.

------------------------------------------------------------------------------------------------------------------

Saturday, November 29, 2008

Postfix - Relaying mails through a third party server

Here I will describe how to relay emails through a third party server from a Postfix server.

Without SMTP AUTH:

If relaying server does not authenticates while relaying through it, use following. Define "relayhost" parameter in /etc/postfix/mail.cf like follows.

relayhost = smtp.relayhost.com

This will do a MX lookup for smtp.relay.com and then send email to smtp.relayhost.com

relayhost = [ smtp.relayhost.com ]

The square brackets turns off MX lookups of smtp.relay.com and simply resolve its IP address and send the emails.

Save the file and reload postfix.

/etc/init.d/postfix reload


With SMTP AUTH:

Most of the relaying server needs you to authenticate with them for relaying through them. Follow these steps to relay with SMTPAUTH.

Add these settings to /etc/postfix/main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =

Create a file called /etc/postfix/sasl_passwd which should contain the username and password for relaying. (It will be provided by relay server provider).

smtp.relayhost.com username:password

The password is enterted in cleartext format, make it readably only by root.

chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd

Create the hash file.
postmap /etc/postfix/sasl_passwd

Make the hash file world readable.
chmod 644 /etc/postfix/sasl_passwd.db

Reload the Postfix config.
/etc/init.d/postfix reload

Teseting the results:

Send an email from local postfix to an external user and it should be relayed through smtp.relayhost.com. Check /var/log/maillog for "relay" log. It will log the errors if there are any configuration mistakes.

------------------------------------------------------------------------------------------------------------------