1

For development purpose we want to set up a mail server (postfix) which directs all mails which are sent via a specific SMTP account to this same account.

edit: The mail shall no longer be sent to the original address.

So we would create different accounts for different projects, and all mail of one project goes to one mailbox.

We currently use this solution: Rewrite recipient of all (except one recipient) outgoing e-mail

But how can we adapt this to different destination addresses based on the SMTP AUTH account?

Alex
  • 676
  • 1
  • 14
  • 37
  • What mail servers? I'm curious about this myself because the auth and delivery is all within the same SMTP transaction so unless you have an SMTP proxy that you can write rules for, I don't see how this could be done easily. – Chase Nov 06 '15 at 17:27
  • I am using postfix – Alex Nov 07 '15 at 16:59
  • Have you tried [sender_bcc_maps](http://www.postfix.org/postconf.5.html#sender_dependent_default_transport_maps) ? – Diamond Nov 11 '15 at 11:13
  • @Alex: Did you had a look into the thread [Redirect specific e-mail address sent to a user, to another user](http://serverfault.com/questions/284702/redirect-specific-e-mail-address-sent-to-a-user-to-another-user)? – gxx Nov 11 '15 at 13:21

2 Answers2

2

Here are two options:

1. use sender_bcc_maps option in Postfix.

sender_bcc_maps (default: empty)

Optional BCC (blind carbon-copy) address lookup tables, indexed by sender address. The BCC address (multiple results are not supported) is added when mail enters from outside of Postfix.

You need to add the following in /etc/postfix/my.cnf:

sender_bcc_maps = hash:/etc/postfix/bcc_maps

And in /etc/postfix/bcc_maps file add the desired mapping:

project1@domain1.com target1@domain1.com
project2@domain1.com target2@domain1.com

Then run:

postmap /etc/postfix/bcc_maps

And restart Postfix.

  1. Sender based redirection

In main.cf:

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access

and in sender_access file:

from_address@domain redirect new_to_address@anotherdomain.

Then postmap /etc/postfix/sender_access and restart postfix

Diamond
  • 9,001
  • 3
  • 24
  • 38
  • Does this reroute the mail or still send them to the original address (which should be avoided)? – Alex Nov 11 '15 at 12:04
  • This sends a blind carbon copy of the original email to the given address. Of course the original mail is also sent. – Diamond Nov 11 '15 at 12:12
  • Unfortunately not fulfilling my use case. Thanks anyways. – Alex Nov 11 '15 at 12:39
  • Well there is an option like sender based redirection: `main.cf: smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access` and sender_access file: `from_address@domain redirect new_to_address@anotherdomain`. Then postmap /etc/postfix/sender_access and restart postfix. May be you can give it a try. – Diamond Nov 11 '15 at 13:31
  • Is the sender checked here always the SMTP auth user? Then you might want to add this as an answer so I can accept it. – Alex Nov 12 '15 at 16:41
  • Well, it works based on the sender address in the email header. You may have to test for yourself to be sure. – Diamond Nov 12 '15 at 17:06
  • I have updated my answer with both options anyway. – Diamond Nov 12 '15 at 17:12
1

This does not answer based on SMTP Auth but does provide a solution based on your needs.

I used canonical maps for this, I set a new vps (centos/ubunbtu whatever) and then set my 'dev' systems to smarthost this box (within the network, 192.168.0 an example) You could do the same with wp-smtp or others, we used interworx so a smarthost worked best.

[root@mx ~]# cat /etc/postfix/main.conf
  recipient_canonical_classes = envelope_recipient
  recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map
  mynetworks = 192.168.0.0/24
  header_checks = regexp:/etc/postfix/header_checks
  relayhost = mailserver.example.com

[root@mx ~]# cat /etc/postfix/header_check
  /^Subject: (.*?)$/ REPLACE Subject: [Dev] $1
[root@mx ~]# cat /etc/postfix/recipient_canonical_map

  /./ webadmins@example.com

*regexp so no need to postmap the files.

As this is a dev environment, from personal experience I wouldn't suggest manipulating your production to accommodate dev, but build systems like this to bridge those systems.

http://www.postfix.org/postconf.5.html#recipient_canonical_maps

Jacob Evans
  • 7,886
  • 3
  • 29
  • 57
  • Yes we were having that in mind - but did not want to set up another VM ... but actually it might be a better solution. – Alex Nov 13 '15 at 17:41