You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

POSTFIX_CONF.txt 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. content="
  3. Postfix configuration for use with PostfixAdmin
  4. -----------------------
  5. Your installation of Postfix MUST support either MySQL or Postgres
  6. lookup tables. You can verify that with 'postconf -m'
  7. Its generally recommended to use proxy as well (which should also appear in
  8. postconf -m) Three main.cf variables are involved:
  9. virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
  10. virtual_alias_maps =
  11. proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
  12. proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
  13. proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
  14. virtual_mailbox_maps =
  15. proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
  16. proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
  17. # if you let postfix store your mails directly (without using maildrop, dovecot deliver etc.)
  18. virtual_mailbox_base = /var/mail/vmail
  19. # or whereever you want to store the mails
  20. # Additional for quota support
  21. virtual_create_maildirsize = yes
  22. virtual_mailbox_extended = yes
  23. virtual_mailbox_limit_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf
  24. virtual_mailbox_limit_override = yes
  25. virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
  26. virtual_overquota_bounce = yes
  27. Where you chose to store the .cf files doesn't really matter, but they will
  28. have database passwords stored in plain text so they should be readable only
  29. by user postfix, or in a directory only accessible to user postfix.
  30. This isn't necessarily all you need to do to Postfix to get up and
  31. running. Also, additional changes are needed for the vacation
  32. autoreply features.
  33. -------------------------
  34. Contents of the files
  35. These are examples only, you will likely have to and want to make some
  36. customizations. You will also want to consider the config.inc.php
  37. settings for domain_path and domain_in_mailbox. These examples
  38. use values of domain_path=YES and domain_in_mailbox=NO
  39. You can create these files (with your values for user, password, hosts and
  40. dbname) automatically by executing this file (sh POSTFIX_CONF.txt).
  41. Please note that the generated files are for use with MySQL.
  42. If you are using PostgreSQL, you'll need to do some changes to the queries:
  43. - PostgreSQL uses a different implementation for boolean values, which means
  44. you'll need to change active='1' to active='t' in all queries
  45. - PostgreSQL does not have a concat() function, instead use e.g.
  46. .... alias.address = '%u' || '@' || alias_domain.target_domain AND ....
  47. mysql_virtual_alias_maps.cf:
  48. user = postfix
  49. password = password
  50. hosts = localhost
  51. dbname = postfix
  52. query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
  53. #expansion_limit = 100
  54. mysql_virtual_alias_domain_maps.cf:
  55. user = postfix
  56. password = password
  57. hosts = localhost
  58. dbname = postfix
  59. query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
  60. mysql_virtual_alias_domain_catchall_maps.cf:
  61. # handles catch-all settings of target-domain
  62. user = postfix
  63. password = password
  64. hosts = localhost
  65. dbname = postfix
  66. query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
  67. (See above note re Concat + PostgreSQL)
  68. mysql_virtual_domains_maps.cf:
  69. user = postfix
  70. password = password
  71. hosts = localhost
  72. dbname = postfix
  73. query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
  74. #query = SELECT domain FROM domain WHERE domain='%s'
  75. #optional query to use when relaying for backup MX
  76. #query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
  77. #expansion_limit = 100
  78. mysql_virtual_mailbox_maps.cf:
  79. user = postfix
  80. password = password
  81. hosts = localhost
  82. dbname = postfix
  83. query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
  84. #expansion_limit = 100
  85. mysql_virtual_alias_domain_mailbox_maps.cf:
  86. user = postfix
  87. password = password
  88. hosts = localhost
  89. dbname = postfix
  90. query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
  91. (See above note re Concat + PostgreSQL)
  92. # For quota support
  93. mysql_virtual_mailbox_limit_maps.cf:
  94. user = postfix
  95. password = password
  96. hosts = localhost
  97. dbname = postfix
  98. query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
  99. -------------------------
  100. More information - HowTo docs that use PostfixAdmin
  101. http://postfix.wiki.xs4all.nl/index.php?title=Virtual_Users_and_Domains_with_Courier-IMAP_and_MySQL
  102. http://wiki.dovecot.org/HowTo/DovecotLDAPostfixAdminMySQL
  103. " # end content
  104. # generate config files out of this file
  105. # to do this, run sh POSTFIX_CONF.txt
  106. POSTFIX_CONF="$0"
  107. map_files="`sed -n '/^mysql.*cf:/ s/://p' < \"$0\"`"
  108. tmpdir="`mktemp -d /tmp/postfixadmin-XXXXXX`" || { echo "Error: could not create tempdir" >&2 ; exit 1; }
  109. echo $tmpdir
  110. echo 'Database host? (often localhost)'
  111. read hosts
  112. test -z "$hosts" && hosts=localhost
  113. echo 'Database name?'
  114. read dbname
  115. test -z "$dbname" && { echo "Error: you did not enter a database name" >&2 ; exit 1; }
  116. echo Database user?
  117. read user
  118. test -z "$user" && { echo "Error: you did not enter a database username" >&2 ; exit 1; }
  119. echo Database password?
  120. read password
  121. test -z "$password" && { echo "Error: you did not enter a database password" >&2 ; exit 1; }
  122. for file in $map_files ; do
  123. (
  124. echo "# $file"
  125. sed -n "/$file:/,/^$/ p" < "$POSTFIX_CONF" | sed "
  126. 1d ; # filename
  127. s/^user =.*/user = $user/ ;
  128. s/^password =.*/password = $password/ ;
  129. s/^hosts =.*/hosts = $hosts/ ;
  130. s/^dbname =.*/dbname = $dbname/ ;
  131. "
  132. ) > "$tmpdir/$file"
  133. done
  134. echo "Config files have been written to $tmpdir. Please check their content and move them to /etc/postfix/sql/."
  135. echo "Do not forget to edit /etc/postfix/main.cf as described in $POSTFIX_CONF."