[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PGSQL-QMAIL - E-Mail Forwarders.



Hi,

I've been working on a bit of an idea that I'm using on my system.

Everythings very functional, and I have an extra table called "aliasinfo",
where it contains information of e-mail forwarders that we host.

Such as columns with

emailaddr, aliasname, aliashost.

Where emailaddr is the emailaddress to be forwarded to, and
aliasname@aliashost is the email address that mail could be received at.

ie, mail sent to aliasname@aliashost forwards to emailaddr.

But, I don't have any specific system in place where qmail is actually
taking advantage of this table, its simply for administrative purposes.

The idea I've been playing with, is to have a .qmail-default in a domain
names directory, to deal with all incoming mail, and work similar to this

where .qmail-default, located in /home/domainnameuser/, contains

|forward `psql -d userdb -c "select emailaddr from aliasinfo where
aliasname='$EXT' and aliashost='$HOST'" | grep -i -q '@' | awk -F" " {'print
$1'}`

...

So say in the above example, a message was sent to myuser@mydomain.

So $EXT = myuser
and $HOST = mydomain

Therefore, it looks up to see if there is a row matchines this, and grabs
the emailaddress field and spits it back as effectively making the
.qmail-default file executing
|forward myuser@anotherdomain.

Hopefully you can follow the idea, basically the psql statement returns the
email address field if the email address that the message was sent to
matches in the aliasinfo table. (my idea was to actually use this
.qmail-default file as a global forwarder for all domains.)

Where the problem lies, is if the lookup fails, ie, the email address does
exist in the database table.. I need to return an exit status of 100 and
spit back an error message, or similar, to make it bounce.. or even better,
if the database lookup fails because of a database problem, the message gets
deferred.

Can anyone suggest a simple way to acheive this?

(Any help with this would be greatly appreciated. My ultimate goal is to
have as much as possible managed via databases).

Regards,

Andrew P Blogg

apblogg@xxxxxxxxxxxxxx