Connect postfix to postgres

Connect postfix to postgres



# Settings required to support virtual mail delivery using lookups in
# the Postgres database.

# A list of all virtual domains serviced by this instance of postfix.
virtual_mailbox_domains = pgsql:/etc/postfix/pgsql/

# Look up the mailbox location based on the email address received.
virtual_mailbox_maps = pgsql:/etc/postfix/pgsql/

# Any aliases that are supported by this system
virtual_alias_maps = pgsql:/etc/postfix/pgsql/
user            = postfix
password        = $password
dbname          = postfix
#hosts          = localhost
query           = SELECT goto FROM alias WHERE address='%s' AND active='1';

Run the query on the database to verify its output:

# psql -U postfix postfix
postfix=>SELECT goto FROM alias WHERE address='[email protected]' AND active='1';

 [email protected]
(1 row)

Make Postfix use this database mapping:

# postconf -e virtual_alias_maps=pgsql:/etc/postfix/pgsql/

Test if the mapping file works as expected:

# postmap -q [email protected] pgsql:/etc/postfix/pgsql/