-1

I need to setup a service that will receive an email such a $uniqueID@domain.com lookup that uniqueID in a MySQL database for an email address then forward the incoming email to the email address (which will be external to the server).

I want to do this with an MTA only not use anything like dovecot in the mix as there wont be any IMAP or POP3 requirements. Can anyone provide a rough guide how I would go about this with exim or postfix?

Rob
  • 121
  • 3
  • 1
    See [this article](https://workaround.org/book/export/html/58), especially on `virtual_alias_maps` section – masegaloeh Oct 09 '14 at 00:22

2 Answers2

1

With exim you can use router like this:

db_fwd:
    driver = redirect
    data   = ${lookup mysql{SELECT `destination` \
                            FROM   `forwarding` \
                            WHERE  `uniqueID`='${quote_mysql:$local_part}'}}
    allow_fail
    allow_defer

Table forwarding contains such rows:

ID  uniqueID      destination
1   awer0zsg9fg   user@domain.tld
Kondybas
  • 6,964
  • 2
  • 20
  • 24
  • Thanks Kondybas I came up with similar for exim-mysql in a test environment but couldn't use in production because of undefined symbols error in mysql.so when using hide mysql_servers problem with the package obviously. – Rob Oct 09 '14 at 08:36
  • May be you have some dependencies broken? In general `exim` have no problems with mysql. – Kondybas Oct 09 '14 at 09:36
  • It sounds like you are using AWS's exim package, which is built incorrectly. For details, see http://serverfault.com/questions/628348/exim-wont-start-error-loading-lookup-module-mysql-so/633908#633908. It's easy to fix, but if you've already got a solution working with Postfix that you understand, you're probably already happy with your current solution. – Todd Lyons Oct 09 '14 at 13:17
1

For anyone else looking it was easier than I expected with postfix: First check for mysql support with: postconf -m

Then: edit main.cf with appropriate defaults (set myhostname,mydomain, mydestination check inet_interfaces isn't bound to just localhost) then add the following to the bottom of main.cf:

virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-forwards.cf

The contents of mysql-forwards.cf should be similar to this:

user = dbuser
password = dbpassword
dbname = database
query = SELECT column AS destination FROM some_table WHERE id='%s'
hosts = mysql-host-name-or-ip
Rob
  • 121
  • 3