Dovecot: Difference between revisions
add standard mailboxes |
Upgrade settings to Dovecot 2.4 and new `dovecot2.settings` option |
||
| Line 66: | Line 66: | ||
enablePAM = false; | enablePAM = false; | ||
# https://doc.dovecot.org/2. | # https://doc.dovecot.org/2.4.4/howto/lmtp/postfix.html | ||
# https://doc.dovecot.org/2. | # https://doc.dovecot.org/2.4.4/howto/sasl/postfix.html | ||
settings = { | |||
# | # dovecot_config_version and dovecot_storage_version must be explicitly set | ||
# to retain compatibility with future updates. | |||
dovecot_config_version = "2.4.2"; | |||
dovecot_storage_version = "2.4.0"; | |||
auth_username_format = "%{user | lower}"; | |||
auth_mechanisms = plain | auth_mechanisms = [ "plain" ]; | ||
passdb { | "passdb passwd-file" = { | ||
driver = passwd-file | driver = "passwd-file"; | ||
passwd_file_path = config.age.secrets.dovecot.path; | |||
} | }; | ||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Setup virtual users = | = Setup virtual users = | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"># /var/spool/mail/vmail needs to be created and owned by vmail | ||
systemd.tmpfiles.rules = [ | |||
"d /var/spool/mail/vmail 0700 vmail vmail -" | |||
]; | |||
services.dovecot2 = { | services.dovecot2 = { | ||
# | settings = { | ||
# dovecot_config_version and dovecot_storage_version must be explicitly set | |||
# to retain compatibility with future updates. | |||
dovecot_config_version = "2.4.2"; | |||
dovecot_config_version = "2.4.0"; | |||
# If config.services.dovecot2.createMailUser is true (which is the default), | |||
# the user defined in mail_uid and mail_gid will be automatically created. | |||
mail_uid = "vmail"; | |||
mail_gid = "vmail"; | |||
# implement virtual users | |||
# https://doc.dovecot.org/2.4.4/howto/virtual/simple_install.html | |||
# store virtual mail under /var/spool/mail/vmail/<DOMAIN>/<USER>/Maildir | |||
mail_driver = "maildir"; | |||
mail_path = "~/Maildir"; | |||
"namespace inbox" = { | |||
"mailbox All" = { auto = "create"; special_use = "\\All"; }; | |||
"mailbox Archive" = { auto = "create"; special_use = "\\Archive"; }; | |||
"mailbox Drafts" = { auto = "create"; special_use = "\\Drafts"; }; | |||
"mailbox Flagged" = { auto = "create"; special_use = "\\Flagged"; }; | |||
"mailbox Junk" = { auto = "create"; special_use = "\\Junk"; autoexpunge = "60d"; }; | |||
"mailbox Sent" = { auto = "create"; special_use = "\\Sent"; }; | |||
"mailbox Trash" = { auto = "create"; special_use = "\\Trash"; autoexpunge = "60d"; }; | |||
}; | |||
"userdb static" = { | |||
fields = { | |||
uid = "vmail"; | |||
gid = "vmail"; | |||
username_format = "%u"; | |||
home = "/var/spool/mail/vmail/%d/%n"; | |||
}; | |||
}; | |||
}; | }; | ||
};</syntaxhighlight> | |||
}; | |||
</syntaxhighlight> | |||
= Connect to postfix via lmtp = | = Connect to postfix via lmtp = | ||
See [[Postfix]] for further setup on postfix side. | See [[Postfix]] for further setup on postfix side. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> # create path for dovecot socket | ||
systemd.tmpfiles.rules = [ | |||
"d /var/spool/postfix 0700 postfix postfix -"; | |||
]; | |||
services.dovecot2 = { | services.dovecot2 = { | ||
# | settings = { | ||
# dovecot_config_version and dovecot_storage_version must be explicitly set | |||
# to retain compatibility with future updates. | |||
dovecot_config_version = "2.4.2"; | |||
dovecot_config_version = "2.4.0"; | |||
protocols = [ "imap" "lmtp" ]; | |||
# https://doc.dovecot.org/2.4.4/howto/lmtp/postfix.html | |||
"service lmtp" = { | |||
service lmtp { | # Note that the socket needs to be placed here because Postfix access is limited to this directory | ||
"unix_listener /var/spool/postfix/dovecot-lmtp" = { | |||
user = "postfix"; | |||
group = "postfix"; | |||
mode = "0600"; | |||
} | }; | ||
} | }; | ||
service auth { | |||
unix_listener /var/spool/postfix/auth { | # https://doc.dovecot.org/2.4.4/howto/sasl/postfix.html | ||
"service auth" = { | |||
"unix_listener /var/spool/postfix/auth" = { | |||
user = "postfix"; | |||
} | group = "postfix"; | ||
} | mode = "0600"; | ||
}; | |||
}; | |||
}; | |||
# postfix connection to dovecot | # postfix connection to dovecot | ||
services.postfix.config = { | services.postfix.config = { | ||
# https://doc.dovecot.org/2. | # https://doc.dovecot.org/2.4.4/howto/lmtp/postfix.html | ||
mailbox_transport = "lmtp:unix:/var/spool/postfix/dovecot-lmtp"; | mailbox_transport = "lmtp:unix:/var/spool/postfix/dovecot-lmtp"; | ||
virtual_transport = "lmtp:unix:/var/spool/postfix/dovecot-lmtp"; | virtual_transport = "lmtp:unix:/var/spool/postfix/dovecot-lmtp"; | ||
# https://doc.dovecot.org/2. | # https://doc.dovecot.org/2.4.4/howto/sasl/postfix.html | ||
smtpd_sasl_type = "dovecot"; | smtpd_sasl_type = "dovecot"; | ||
smtpd_sasl_path = "/var/spool/postfix/auth"; | smtpd_sasl_path = "/var/spool/postfix/auth"; | ||
| Line 167: | Line 178: | ||
smtpd_recipient_restrictions = "permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"; | smtpd_recipient_restrictions = "permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 179: | Line 183: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.dovecot2 = { | services.dovecot2 = { | ||
settings = { | |||
# dovecot_config_version and dovecot_storage_version must be explicitly set | |||
# to retain compatibility with future updates. | |||
dovecot_config_version = "2.4.2"; | |||
dovecot_config_version = "2.4.0"; | |||
# https://doc.dovecot.org/2.4.4/core/config/ssl.html | |||
ssl = true; # see also "required" | |||
ssl_server_cert_file = "${sslCertDir}/fullchain.pem"; | |||
ssl_server_key_file = "${sslCertDir}/key.pem"; | |||
ssl_server_ca_file = "${sslCertDir}/chain.pem"; | |||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 199: | Line 212: | ||
= mail_crypt plugin (encryption at rest) = | = mail_crypt plugin (encryption at rest) = | ||
{{Outdated}} | |||
The following seems to make mail_crypt work in its per-user/per-folder mode (note that this mode is still described as 'not production quality' in the dovecot docs): | The following seems to make mail_crypt work in its per-user/per-folder mode (note that this mode is still described as 'not production quality' in the dovecot docs): | ||