Wednesday, April 11, 2012

Where I work, we had an interesting request from a client.  This client is a mass mailer. And they wanted a means to self configure exim, for which ip a domain must be listening on.

Heres how I did it.

First we create the router:
vi /etc/exim4/conf.d/router/350_exim4-config_vdom_aliases
vdom_aliases:
      driver = redirect
      allow_defer
      allow_fail
      domains = dsearch;
/path/for/client/mail/virtual
      data = ${expand:${lookup{$local_part}lsearch*@{/path/for/client/mail/virtual/$domain}}}
      retry_use_local_part
      pipe_transport   = address_pipe
      file_transport   = address_file
      no_more


Next we copy the orignal remote_smtp transport
cp /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp  /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_new

vi  /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_new

 remote_smtp_new:
  debug_print = "T: remote_smtp for $local_part@$domain"
  driver = smtp
.ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
  hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
.endif
.ifdef REMOTE_SMTP_HEADERS_REWRITE
  headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
.endif
.ifdef REMOTE_SMTP_RETURN_PATH
  return_path = REMOTE_SMTP_RETURN_PATH
.endif
.ifdef REMOTE_SMTP_HELO_DATA
  helo_data=REMOTE_SMTP_HELO_DATA
.endif
.ifdef DKIM_DOMAIN
dkim_domain = DKIM_DOMAIN
.endif
.ifdef DKIM_SELECTOR
dkim_selector = DKIM_SELECTOR
.endif
.ifdef DKIM_PRIVATE_KEY
dkim_private_key = DKIM_PRIVATE_KEY
.endif
.ifdef DKIM_CANON
dkim_canon = DKIM_CANON
.endif
.ifdef DKIM_STRICT
dkim_strict = DKIM_STRICT
.endif
.ifdef DKIM_SIGN_HEADERS
dkim_sign_headers = DKIM_SIGN_HEADERS
.endif
interface = ${if exists {
/path/for/client/mail/domainiplist}{${lookup{$sender_address_domain}lsearch*{/path/for/client/mail/domainiplist}{$value}{}}}{}}
helo_data = ${if exists {
/path/for/client/mail/domainhelolist}{${lookup{$sender_address_domain}lsearch*{/path/for/client/mail/domainhelolist}{$value}{$primary_hostname}}}{$primary_hostname}}

Then 

vi  /etc/exim4/conf.d/main/000_localmacros
MAIN_LOCAL_DOMAINS = @:localhost:dsearch;/path/for/client/mail/virtual

No comments:

Post a Comment