PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
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.

221 lines
5.0 KiB

  1. # Example configuration
  2. The below covers some default(ish) configuration things for using Postfix, Dovecot with PostgreSQL.
  3. # Postfix
  4. Assumptions :
  5. * Mail is delivered into /var/mail/vmail/foo@example.com/
  6. * The user with id 8 is used for ownership of mail files.
  7. * PostgreSQL is running on the local server
  8. * Dovecot is running on the local server, and SASL is used to allow authenticated clients to mail out.
  9. ## /etc/postfix/main.cf
  10. The proxy: bits are optional, you may need to install an additional postfix package on your server to enable them.
  11. i.e. proxy:pgsql:/path/to/file is equivalent to pgsql:/path/to/file. Use of 'proxy:' may lead to a small performance boost.
  12. ```
  13. relay_domains = $mydestination, proxy:pgsql:/etc/postfix/pgsql/relay_domains.cf
  14. virtual_alias_maps = proxy:pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
  15. virtual_mailbox_domains = proxy:pgsql:/etc/postfix/pgsql/virtual_domains_maps.cf
  16. virtual_mailbox_maps = proxy:pgsql:/etc/postfix/pgsql/virtual_mailbox_maps.cf
  17. virtual_mailbox_base = /var/mail/vmail
  18. virtual_mailbox_limit = 512000000
  19. virtual_minimum_uid = 8
  20. virtual_transport = virtual
  21. virtual_uid_maps = static:8
  22. virtual_gid_maps = static:8
  23. local_transport = virtual
  24. local_recipient_maps = $virtual_mailbox_maps
  25. ```
  26. and for Postfix SASL support :
  27. ```
  28. # SASL Auth for SMTP relaying
  29. smtpd_sasl_type = dovecot
  30. smtpd_sasl_path = private/auth
  31. smtpd_sasl_authenticated_header = yes
  32. smtpd_sasl_auth_enable = yes
  33. smtpd_sasl_security_options = noanonymous
  34. broken_sasl_auth_clients = yes
  35. ```
  36. ## /etc/postfix/pgsql/relay_domains.cf
  37. ```
  38. user = postfix
  39. password = whatever
  40. hosts = localhost
  41. dbname = postfix
  42. query = SELECT domain FROM domain WHERE domain='%s' and backupmx = true
  43. ```
  44. ## /etc/postfix/pgsql/virtual_alias_maps.cf
  45. ```
  46. user = postfix
  47. password = whatever
  48. hosts = localhost
  49. dbname = postfix
  50. query = SELECT goto FROM alias WHERE address='%s' AND active = true
  51. ```
  52. ## /etc/postfix/pgsql/virtual_domains_maps.cf
  53. ```
  54. user = postfix
  55. password = whatever
  56. hosts = localhost
  57. dbname = postfix
  58. #query = SELECT domain FROM domain WHERE domain='%s'
  59. #optional query to use when relaying for backup MX
  60. query = SELECT domain FROM domain WHERE domain='%s' and backupmx = false and active = true
  61. ```
  62. ## /etc/postfix/pgsql/virtual_mailbox_limits.cf
  63. ```
  64. # Used for quota
  65. user = postfix
  66. password = whatever
  67. hosts = localhost
  68. dbname = postfix
  69. query = SELECT quota FROM mailbox WHERE username='%s'
  70. ```
  71. ## /etc/postfix/pgsql/virtual_mailbox_maps.cf
  72. ```
  73. user = postfix
  74. password = whatever
  75. hosts = localhost
  76. dbname = postfix
  77. query = SELECT maildir FROM mailbox WHERE username='%s' AND active = true
  78. ```
  79. # Dovecot
  80. (This is from version 2.2.27, Debian Stretch)
  81. ## /etc/dovecot/dovecot.conf
  82. ```
  83. mail_location = maildir:/var/mail/vmail/%u/
  84. namespace inbox {
  85. type = private
  86. inbox = yes
  87. location =
  88. mailbox Drafts {
  89. special_use = \Drafts
  90. }
  91. mailbox Junk {
  92. special_use = \Junk
  93. }
  94. mailbox Sent {
  95. special_use = \Sent
  96. }
  97. mailbox "Sent Messages" {
  98. special_use = \Sent
  99. }
  100. mailbox Trash {
  101. special_use = \Trash
  102. }
  103. prefix =
  104. }
  105. protocols = "imap pop3"
  106. # Requires certificates ...
  107. #ssl = yes
  108. #ssl_cert = </etc/dovecot/private/something.pem
  109. #ssl_key = </etc/letsencrypt/certs/something.key
  110. login_greeting = My Mail Server
  111. # http://wiki2.dovecot.org/Authentication/Mechanisms
  112. # login is for outlook express ...
  113. auth_mechanisms = plain login
  114. #auth_debug = yes
  115. #auth_debug_passwords=yes
  116. # Postfix - Sasl auth support.
  117. service auth {
  118. # Postfix smtp-auth
  119. unix_listener /var/spool/postfix/private/auth {
  120. mode = 0660
  121. user = postfix
  122. group = postfix
  123. }
  124. # Auth process is run as this user.
  125. user = postfix
  126. group = postfix
  127. }
  128. service imap {
  129. executable = imap
  130. }
  131. userdb {
  132. driver = sql
  133. args = /etc/dovecot/dovecot-sql.conf
  134. }
  135. passdb {
  136. driver = sql
  137. args = /etc/dovecot/dovecot-sql.conf
  138. }
  139. # Needs to match Postfix virtual_uid_maps
  140. first_valid_uid = 8
  141. # disallow or allow plaintext auth.
  142. disable_plaintext_auth = yes
  143. mail_plugins = $mail_plugins zlib
  144. plugin {
  145. zlib_save_level = 6
  146. zlib_save = gz
  147. }
  148. protocol imap {
  149. mail_plugins = $mail_plugins imap_zlib
  150. }
  151. mail_max_userip_connections = 50
  152. log_path = /var/log/dovecot.log
  153. ```
  154. ## /etc/dovecot/dovecot-sql.conf
  155. Ideally dovecot has a different read only database user.
  156. ```
  157. connect = host=localhost dbname=postfix user=dovecot password=whatever
  158. driver = pgsql
  159. # Default password scheme - change to match your Postfixadmin setting.
  160. # depends on your $CONF['encrypt'] setting:
  161. # md5crypt -> MD5-CRYPT
  162. # md5 -> PLAIN-MD5
  163. # cleartext -> PLAIN
  164. default_pass_scheme = MD5-CRYPT
  165. # Query to retrieve password. user can be used to retrieve username in other
  166. # formats also.
  167. password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'
  168. # Query to retrieve user information, note uid matches dovecot.conf AND Postfix virtual_uid_maps parameter.
  169. user_query = SELECT '/var/vmail/mail/' || maildir AS home, 8 as uid, 8 as gid FROM mailbox WHERE username = '%u' AND active = '1'
  170. ```