I'm setting up Postfix + PostgreSql on FreeBsd to host my email server. I'm about 50% done.

I'm confused with several *.cf files and can't figure out which I should use for this.

I own several domains, say: domain1.com, domain2.com and domain3.com.

Where exactly should I specify these 3 domains? In what config file of Postfix? Thus my Postfix will only send through and receive emails for them?

closed as off-topic by Jenny D, kubanczyk, MadHatter, Kenny Rasschaert, Khaled Jun 5 '18 at 10:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    I'm voting to close this question as off-topic because the user gives no indication of having read even the most basic how-to for the system they're trying to configure, and ServerFault is not a manual-reading service. – Jenny D May 22 '18 at 10:29
  • @JennyD ahahahahhaaaa – Ивандронович May 22 '18 at 11:28

First you have to choose if you want info@domain1.com to be a different address vs info@domain2.com: I assume you do, otherwise you wouldn't need Postgresql in the picture.

The second step is to tell Postfix where to find information on domains and email accounts: it looks like you want to use Postgresql instead of a local text file (see http://www.postfix.org/VIRTUAL_README.html#local_vs_database), so you need to:

  1. create a Postgresql account for Postfix (e.g. createuser -U postgres --pwprompt postfix)
  2. create a postfix_db db
  3. grant access to the db to user postfix (e.g. GRANT ALL PRIVILEGES ON DATABASE postfix_db TO postfix_user;)
  4. create an aliases, users and domains tables:

    mail=# CREATE TABLE aliases ( alias text NOT NULL, email text NOT NULL );

    mail=# CREATE TABLE users ( email text NOT NULL, password text NOT NULL, maildir text NOT NULL, created timestamp with time zone DEFAULT now() );

    mail=# CREATE TABLE domain ( domain varchar(50) NOT NULL, node varchar(50), comment varchar(500), PRIMARY KEY (domain) );

Finally you need to tell Postfix how to fetch information from these tables (see http://www.postfix.org/PGSQL_README.html). Add to main.cf:

virtual_alias_maps = pgsql:/etc/postfix/virtual_alias_maps.cf
virtual_mailbox_domains = pgsql:/etc/postfix/virtual_mailbox_domains.cf
virtual_mailbox_maps = pgsql:/etc/postfix/virtual_mailbox_maps.cf

The content of virtual_alias_maps.cf will be like this:

user = postfix
password = your-pass
hosts = localhost
dbname = postfix_db
query = SELECT email FROM aliases WHERE alias='%s'

The content of other .cf files will be similar: user, pass, host to connect to the db, name of db and query to fetch the required information. Postfix will replace the format strings as needed.

This should be enough information to understand how things work from an high perspective. Once you have a general understanding of what's going on under the hood you can try this gist: https://gist.github.com/solusipse/7ed8e1da104baaee3f05 or this howto: https://github.com/postfixadmin/postfixadmin/blob/master/DOCUMENTS/Postfix-Dovecot-Postgresql-Example.md

  • Where exactly should I specify these 3 domains? -- that was question – Ивандронович May 22 '18 at 6:29
  • you haven't even answered to my question – Ивандронович May 22 '18 at 6:30
  • Inside the domain table, in the postfix_db database, in Postgresql – Luca Gibelli May 22 '18 at 6:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.