# [SOLVED] Postfix: Forward email and local delivery with LDAP

## ckoeber

[SOLVED]

Hello,

I would like for a user to have the ability to forward email to an external account BUT I also need to keep a copy of that message using PostfFix. So, I have the following template that I believe can work for an alias file for an LDAP setup:

ldap-alias.cf:

```
 

server_host = [LDAP Server here]

search_base = [Search Base Here]

version=3

timeout = 10

bind = yes

bind_dn = [bind-dn here]

bind_pw = [bind password here]

query_filter = (mail=%s)

result_attribute = (local account?) + (forwarding account?)
```

Now, I have a separate attribute called vacationForward within my LDAP system that contains the forwarding address. My local email address is stored as mail within LDAP.

The problem is that I would need to return TWO results, correct? I need to return the local account and the forwarding account, correct?

Has anyone done this with Postfix?

Thanks for any help with this.Last edited by ckoeber on Fri Oct 22, 2010 6:14 pm; edited 1 time in total

----------

## nativemad

Hi, 

the alias query should return a comma separated list of destination addresses... Therefore you would need a third account for the local delivery or you'll see some looping i suppose!? 

I made such things in the maildrop-delivery script. You think you should also be able to do it with procmail or such.

good luck

----------

## ckoeber

 *nativemad wrote:*   

> Hi, 
> 
> the alias query should return a comma separated list of destination addresses... Therefore you would need a third account for the local delivery or you'll see some looping i suppose!? 
> 
> I made such things in the maildrop-delivery script. You think you should also be able to do it with procmail or such.
> ...

 

Thanks for the help, I figured this out. Your suggestion was close to the mark!

I am posting a separate reply for other people.

----------

## ckoeber

OK, so I figured this out:

To forward email and retain a local copy with LDAP, here is tutorial configuration:

Put the text below (with your modifications) in a file, preferably in the same directory where other Postfix configuration files are.

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

```
server_host = [LDAP HOST]

search_base = [Search Base - i.e. (ou=Where to Search,dc=example,dc=com)]

version=3

timeout = 10

size_limit = 1      (Directive to inform the LDAP searching utility that only one SET of results should come back per search (i.e. if I search for one CN then only one CN with all resultant attributes should be returned.)

bind = yes

bind_dn = [Bind DN for searching]

bind_pw = [Bind Password]

query_filter = ([Attribute to search for here]=%s)                  - Note that this is the address of the email being recieved.

result_attribute = [Attribute Containing Local Address], [Attribute Containing External Address], [More Attributes containing addresses, separated by commas]
```

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

Once this is done, put your ldap:[Location of above file] directive within a virtual_alias_maps or alias_maps directive in your main configuration file. This depends on whether the address being delivered to is read as a local or virtual domain. A completely working example looks something like what I have below:

ldap-forward-example.cf:

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

```
server_host = ldap-server.example.com

search_base = ou=People,dc=example,dc=com

version=3

timeout = 10

size_limit = 1

bind = yes

bind_dn = cn=Manager,dc=example,dc=com

bind_pw = password

query_filter = (mail=%s)

result_attribute = mail, addressToForward
```

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

Within the main.cf file:

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

```
#For virtual domains:

virtual_alias_maps = ldap:/etc/postfix/ldap-forward-example.cf

#

# OR

#

#For local domains:

alias_maps = hash:/etc/mail/aliases,ldap:/etc/postfix/ldap-forward-example.cf
```

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

That should be it. Hope this helps someone. I have been searching all over for this.Last edited by ckoeber on Sat Oct 23, 2010 5:42 pm; edited 1 time in total

----------

## nativemad

ok, nice trick with the "mail, field"!  :Razz: 

I've got almost the same, but without a local copy... postalias is my field with the comma separated list as value

```
result_attribute = postalias

```

----------

## seyazar

Hi,

i applied these settings and it's worked, but after that i create ne schema element for forward address(first i used description attribute), now it doesn't work how can i investigate this or debug ?

thanks in advance.

Selçuk

 *ckoeber wrote:*   

> OK, so I figured this out:
> 
> To forward email and retain a local copy with LDAP, here is tutorial configuration:
> 
> Put the text below (with your modifications) in a file, preferably in the same directory where other Postfix configuration files are.
> ...

 

----------

