I have exim4 configured to forward email for certain addresses.
The addresses are on virtual domains for which the server is the primary MX.
Other addresses on these domains are delivered to local mailboxes, but the addresses configured to forward go to external domains for which the server is not an MX and the mail should not be delivered to a local mailbox.
e.g. if the server is the primary MX for example.com
, it should deliver mail locally for user1@example.com
but user2@example.com
should forward to user2realname@gmail.com
.
All data for virtual domains and addresses is stored in MySQL.
The server OS is Debian.
The config for the forwarding router (in /etc/exim4/conf.d/router/400_exim4-config_mysql_forward
is as follows:
mysql_forward:
debug_print = "R: forwarder(mysql) for $local_part@$domain"
driver = redirect
no_verify
no_expn
check_ancestor
forbid_smtp_code = true
skip_syntax_errors
domains = +local_domains
data = ${lookup mysql{SELECT forward_to FROM mail_forwarders WHERE domain='${quote_mysql:$domain}' AND localpart='${quote_mysql:$local_part}' AND active=1} {${sg{$value}{\\n}{, }}}}
exim -bt user2@example.com
outputs something like:
R: forwarder(mysql) for user2@example.com
R: dnslookup for user2realname@gmail.com
user2realname@gmail.com
<-- user2@example.com
router = dnslookup, transport = remote_smtp
host gmail-smtp-in.l.google.com [74.125.133.27] MX=5
host alt1.gmail-smtp-in.l.google.com [173.194.222.27] MX=10
host alt2.gmail-smtp-in.l.google.com [74.125.200.27] MX=20
host alt3.gmail-smtp-in.l.google.com [74.125.23.27] MX=30
host alt4.gmail-smtp-in.l.google.com [173.194.72.27] MX=40
I can send mail with a local command and it is forwarded successfully.
However, when sending mail from an outside source, the mail is rejected with 550 Unrouteable address
, e.g.:
telnet mailserver.example.com 25
Connected to mailserver.example.com.
Escape character is '^]'.
220 mailserver.example.com ESMTP
EHLO office.mylocaldomain.com
250-mailserver.example.com Hello office.mylocaldomain.com [21.22.23.24]
250-SIZE 52428800
250-PIPELINING
250 HELP
MAIL FROM: <user@mylocaldomain.com>
250 OK
RCPT TO: <user2@example.com>
550 Unrouteable address
QUIT
I'm sure more config will be required to diagnose this fully. Please ask and I will provide.