LoginSignup
0
0

More than 5 years have passed since last update.

Connect postfix to postgres

Last updated at Posted at 2017-01-17

Connect postfix to postgres

cf. https://wiki.gentoo.org/wiki/Complete_Virtual_Mail_Server/Postfix_to_Database#Postgres :thumbsup:

/etc/postfix/main.cf

#
# 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/virtual_mailbox_domains.cf

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

# Any aliases that are supported by this system
virtual_alias_maps = pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
/etc/postfix/pgsql/virtual_alias_maps.cfvirtual_alias_maps
# virtual_alias_maps.cf
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='testuser@example.com' AND active='1';

       goto       
------------------
 testuser@example.com
(1 row)

Make Postfix use this database mapping:

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

Test if the mapping file works as expected:

# postmap -q jack@example.org pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0