mail gateway relay_recipient_maps point to Zimbra
Working up to a Zimbra migration...
I would like to keep my mail gateway as the primary relay smarthost for zimbra and other domains in use. The gateway runs postifx.
I figure in addition to static maps for other domains, I can point the gateway's relay_recipient_maps at LDAP on the Zimbra server for a dynamic map. Or I could regularly export all valid recipients on the zimbra machine and place it in a map on the gateway.
I think the export is probably the way to go. It would allow the Zimbra server to go down without bouncing any mails.
It looks like the config for such a map is fortunately in /opt/zimbra/conf/ldap-vam.cf
Code:
server_host = ldap://a.host.name:389
server_port = 389
search_base =
query_filter = (&(|(zimbraMailDeliveryAddress=%s)(zimbraMailAlias=%s)(zimbraMailCatchAllAddress=%s))(zimbraMailStatus=enabled))
result_attribute = zimbraMailDeliveryAddress,zimbraMailForwardingAddress,zimbraPrefMailForwardingAddress,zimbraMailCatchAllForwardingAddress
version = 3
bind = no
timeout = 30
Which for my gateway would look something like
Code:
relay_recipient_maps =
ldap:$config_directory/relay_recipients.zimbra.cf
hash:$config_directory/relay_recipients.sub.domain
hash:$config_directory/relay_recipients.other.sub.domain
But to do a full recipient extract, is the following the best way to do that?
ldapsearch -H 'ldap://a.host.name/' -x '(&(|(zimbraMailDeliveryAddress=*)(zimbraMailAlias =*)(zimbraMailCatchAllAddress=*))(zimbraMailStatus =enabled))'
generate static recipient_map
Maybe no one is doing this. It seems a little more comforting to have a static recipient list than LDAP since I wouldn't want the gw to bounce messages if Zimbra was down on accident or purpose.
Here's some code to generate such a list.
Code:
#!/bin/bash
################################################################################
# $Id: ldap2recipients,v 1.3 2007/03/21 18:27:14 bewley Exp $
#-------------------------------------------------------------------------------
# Use this script to generate a list of valid recipients on a Zimbra server.
# The output is suitable for use by postfix recipient_maps. You might want
# this if you have an SMTP gateway catching email from the internet before it
# gets to Zimbra. Postfix could just use LDAP, but what if Zimbra is down?
################################################################################
LDAP_HOST=zimbra.dom.ain
# domain to search in. this is not needed if running as zimbra on localhost
SEARCH_BASE='dc=dom,dc=ain'
# default domain for email addresses
DOMAIN='dom.ain'
# domains that map to the same as above
DOMAIN_ALIASES='mail.dom.ain legacy.dom.ain'
OUT=`mktemp -t recipients.XXXXXXXX`
ldapsearch -x -H "ldap://${LDAP_HOST}/" -b "${SEARCH_BASE}" \
'(& (|
(zimbraMailDeliveryAddress=*)
(zimbraMailAlias=*)
(zimbraMailCatchAllAddress=*)
)
(zimbraMailStatus=enabled)
)' \
| grep -E '^zimbraMailDeliveryAddress|^zimbraMailAlias' \
| sed 's/.*: \(.*\)$/\1/' \
> $OUT
# one entry per domain and domain alias
cat $OUT | while read email; do
user=`echo $email|sed s/@${DOMAIN}$//`
for dom in $DOMAIN $DOMAIN_ALIASES; do
echo "${user}@${dom} ok";
done
done
rm $OUT