Exim4 and Virtual Users .forward Files

Some days ago I began to wonder why some mails in mail account were filtered by Exims .forward file why some are not. It took until today that I found out what was the problem and how to fix it.

I implemented a virtual users/domains system for Exim using several different documentations and tutorials. Right now some parts of my system include the documentation on


Now the problem is that the userforward router is only working for accounts whose $local_part is an existing system user. I came up with the following additional router that solves the problem. Its written for the MySQL table layout that is specified in the Tutorial above.

  debug_print = "R: virtualuserforward for $local_part@$domain"
  driver = redirect
  domains = +local_domains
  file = ${lookup mysql{SELECT CONCAT(home,'.forward') AS forward FROM users \
        WHERE id='${quote_mysql:$local_part}@${quote_mysql:$domain}'}}
  directory_transport = address_directory
  file_transport = address_file
  pipe_transport = address_pipe
  reply_transport = address_reply

  user = ${lookup mysql{SELECT uid FROM users \
        WHERE id='${quote_mysql:$local_part}@${quote_mysql:$domain}'}}
  group = ${lookup mysql{SELECT gid FROM users \
        WHERE id = '${quote_mysql:$local_part}@${quote_mysql:$domain}'}}

Now each virtual user is using the .forward file in its actual system user account home directory. The next problem was: $home is not defined in this case in the .forward file syntax: Its empty. So replacing $home with its obvious path leads to the final solution.

More about: Linux

Sign up for my newsletter to get notified when I post new content on this blog and with the occasional exclusive content only for subscribers.

By clicking on the Subscribe button I am giving my consent for Benjamin Eberlei to hold my name and email address for the purposes of contacting me with a newsletter on the topics of this blog. You can unsubscribe with one click at any time and withdraw your consent. No spam. I will never share your e-mail address. Privacy Policy