How to Deliver Email to Maildir Virtual Users Using LMTP

You want a reliable way to deliver email to Maildir-format virtual users. LMTP, or local mail transfer protocol, gives you a modern solution for this task. When you use LMTP with Hong Kong hosting, you gain better performance and easier management for virtual mailboxes. Correct permissions, DNS records, and SSL certificates help you keep your setup secure and stable.
Key Takeaways
LMTP improves email delivery performance for Maildir virtual users by offloading processing and reducing strain on servers.
Setting up correct permissions and SSL certificates enhances the security and stability of your email system.
Use Unix sockets for LMTP communications to ensure secure and reliable email delivery.
Regularly test your email setup and review logs to confirm successful message delivery and troubleshoot issues.
Consider adding features like Sieve for message filtering and quota management to enhance user experience and resource management.
Why Use LMTP for Maildir Delivery
LMTP vs SMTP for Local Delivery
You may wonder why you should choose lmtp instead of SMTP for local delivery. LMTP offers several advantages when you want to deliver email to virtual users.
LMTP decreases the burden on your back-end message stores. It offloads processing to relays, which scale better as your system grows.
You avoid putting too much strain on LDAP servers. This helps prevent bottlenecks in large email systems.
LMTP minimizes the number of message queues. This makes it easier for you to track messages and manage your system.
When you use lmtp delivery, you simplify your setup. You also improve efficiency compared to traditional SMTP. Postfix works well with lmtp, especially when you use dovecot as your delivery agent.
Benefits for Virtual Users
LMTP brings important benefits for virtual users who use the maildir format.
LMTP avoids local delivery issues. It lets you store mail centrally in an IMAP mailstore until users access their messages.
The MTA can run in unprivileged mode when you use lmtp. This reduces the risk of running dangerous code and improves security.
Dovecot supports lmtp natively. You get reliable delivery to maildir, and you can manage permissions more easily.
Tip: When you set up dovecot with lmtp, you make your email system more secure and easier to maintain. You also give your virtual users a better experience.
You should always check that your maildir directories have the right permissions. This ensures that lmtp delivery works smoothly for every virtual user.
Architecture and Prerequisites
System Requirements
You need to prepare your system before you set up lmtp delivery for maildir virtual users. Start by making sure you have all the necessary components. Here is a checklist to guide your preparation:
Install and configure the postfix email server.
Set up dovecot with lmtp support in the configuration file.
Create maildir directories for each virtual user.
Add a dedicated vmail user to manage mail storage.
Set up DNS records for your domain.
Obtain and install SSL certificates for secure connections.
Configure UNIX sockets for SMTP authentication and mail delivery.
Establish firewall rules to allow only the required traffic.
Manage services to keep dovecot and postfix running at all times.
Test your configuration to confirm that everything works as expected.
You should check each item on this list before you move forward. This will help you avoid common problems during configuration.
User and Directory Setup
You must create a vmail user and set up the correct directory structure for maildir storage. Assign ownership of all maildir folders to the vmail user. This step prevents permission errors and keeps your system secure.
When you bind lmtp to a Unix socket, you improve the reliability of your email delivery. The operating system enforces access control through file permissions. Only trusted local processes can access the socket. This reduces the risk of unauthorized access or privilege escalation. You should always choose Unix domain sockets over TCP for lmtp communications in your dovecot configuration.
Note: Misconfigured transport mechanisms can expose your system to security risks. Always review your dovecot and postfix configuration files to ensure proper permissions and paths.
You will create a stable foundation for your virtual mail system by following these steps. Careful setup of users, directories, and configuration files ensures smooth operation and secure maildir delivery.
Install and Configure Dovecot LMTP
Dovecot LMTP Installation
You need to install Dovecot and enable the dovecot lmtp server before you can use lmtp delivery. Start by choosing the right package manager for your Linux distribution. The table below shows the most common commands:
Linux Distribution | Package Manager | Command to Install Dovecot |
|---|---|---|
Ubuntu/Debian | apt | sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y |
CentOS/Rocky Linux | dnf | sudo dnf install dovecot -y |
After you install dovecot, you must configure the maildir location for your virtual users. Open the configuration file and set the mail_location parameter. Create the necessary directories for mail storage. Assign ownership to the vmail user and group. This step prevents permission errors during dovecot lmtp delivery.
Follow these steps for a basic dovecot setup:
Install dovecot packages for your system.
Edit
/etc/dovecot/conf.d/10-mail.confand setmail_location = maildir:/var/mail/vhosts/%d/%n.Create directories for your domain and mail storage.
Add the vmail user and group, then set ownership for all mail folders.
Enable IMAPs, POP3s, and dovecot lmtp services in the configuration files.
Update authentication settings for secure access.
Tip: Always check your dovecot setup for correct permissions and paths. This step ensures reliable lmtp delivery.
LMTP Socket Configuration
You must bind the dovecot lmtp server to a Unix socket for secure delivery. The socket is usually defined as /var/cyrus/socket/lmtp. Use the command lmtpd -U 100 to bind lmtp to the socket. Make sure the socket name matches your dovecot configuration. Set permissions so only trusted services like postfix and dovecot can access the socket.
The Unix socket restricts access to local processes.
File permissions protect your maildir and dovecot lmtp server.
You improve security and reliability for your virtual email system.
Note: Review your dovecot and postfix configuration files after every change. This habit helps you avoid mistakes and keeps your lmtp delivery stable.
Configure Postfix Email Server for LMTP Delivery
Setting up your postfix email server to deliver email to virtual users through lmtp is a crucial step in your mail server setup. You will connect postfix and dovecot so that all messages reach the correct maildir folders. This process ensures reliable lmtp delivery and keeps your virtual mailboxes organized and secure.
Postfix Main Settings
You need to adjust several main settings in your postfix configuration to enable lmtp delivery with dovecot. These changes help you deliver email efficiently and securely. Follow these steps to connect postfix and dovecot using a Unix socket:
Enable the lmtp protocol in your dovecot configuration. Open
/etc/dovecot/dovecot.confand addlmtpto the protocols list.Set up the lmtp socket in
/etc/dovecot/conf.d/10-master.conf. Make sure the socket path matches what postfix will use.Configure lmtp settings in
/etc/dovecot/conf.d/20-lmtp.conf. Set mail plugins and the postmaster address as needed.Edit
/etc/postfix/main.cfto setvirtual_transport = lmtp:unix:private/dovecot-lmtp. This tells postfix to deliver email to dovecot using the Unix socket.If you want to deliver email to local system users, set
mailbox_transport = lmtp:unix:private/dovecot-lmtp.
You should also update other postfix settings to support lmtp delivery and secure authentication:
Set
mailbox_transport = lmtp:unix:private/dovecot-lmtpin your main.cf file.Set
mailbox_size_limit = 0andmessage_size_limit = 0to avoid delivery problems with large messages.For SASL authentication, add:
smtpd_sasl_type = dovecotsmtpd_sasl_path = private/authsmtpd_sasl_auth_enable = yessmtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
Remove or comment out
virtual_mailbox_baseif dovecot manages the mailbox layout.
Tip: Always reload postfix after making changes to your configuration files. Use
postfix reloadto apply your updates.
These settings allow postfix to communicate directly with dovecot for lmtp delivery. You create a secure and efficient path for every email that enters your system.
Virtual User and Maildir Mapping
Mapping virtual users to their maildir locations is a key part of your virtual mailbox setup. You need to tell postfix where to store each user’s messages and which user owns each mailbox. This mapping keeps your virtual mailboxes organized and ensures dovecot can access every message.
Here is a table that shows the main postfix settings for virtual user mapping:
Setting | Value |
|---|---|
virtual_mailbox_domains | example.com (add more domains as needed) |
virtual_mailbox_base | /var/mail/vhosts |
virtual_mailbox_maps | hash:/etc/postfix/vmailbox |
virtual_minimum_uid | 100 |
virtual_uid_maps | static:5000 |
virtual_gid_maps | static:5000 |
virtual_alias_maps | hash:/etc/postfix/virtual |
virtual_transport | lmtp:unix:private/dovecot-lmtp |
Command to update virtual | postmap /etc/postfix/virtual |
Command to update vmailbox | postmap /etc/postfix/vmailbox |
Command to reload Postfix | postfix reload |
You define your virtual_mailbox_domains to list all domains you want to handle. The virtual_mailbox_base tells postfix where to store maildir folders. The virtual_mailbox_maps file links each email address to its maildir path. For example:
info@example.com example.com/info/ sales@example.com example.com/sales/
@example.com example.com/catchall
You set virtual_uid_maps and virtual_gid_maps to match the vmail user and group. This step ensures dovecot has the right permissions to access every mailbox. The virtual_alias_maps file lets you create aliases or forward addresses as needed.
The mapping process works like this:
Configuration Parameter | Description |
|---|---|
virtual_mailbox_base | Sets the base location for all mailboxes. |
virtual_mailbox_maps | Maps each recipient address to the correct maildir path. |
virtual_uid_maps | Assigns the user ID for mailbox ownership. |
virtual_gid_maps | Assigns the group ID for mailbox ownership. |
After you update your mapping files, run the postmap command to generate the necessary database files. Then reload postfix to activate your changes.
Note: Always check that your maildir directories exist and have the correct ownership. This step prevents permission errors and ensures smooth lmtp delivery.
By following these steps, you connect postfix and dovecot for seamless lmtp delivery. You deliver email to every virtual user with accuracy and security. Your mail server setup will support virtual mailboxes and provide reliable delivery for all users.
Testing and Troubleshooting LMTP Delivery
Verifying Email Delivery
You should always check that your system delivers messages to the correct Maildir folders. Start by sending a test message to a virtual user. You can use several tools to confirm that the message arrived:
Run
ls -l /home/chris/Maildir/newto see if new messages appear in the Maildir.Use
less /home/chris/Maildir/new/<filename>to read the contents of a specific message.Open your Maildir with a client like
mutt -f ~/Maildirfor easy navigation and reading.
You can also review log files to confirm successful delivery. The following table shows which logs to check and their purpose:
Log File | Purpose |
|---|---|
dovecot-lmtp.log | Confirms receipt of email by Dovecot LMTP |
exim/mainlog | Confirms delivery status of emails to LMTP |
To see recent LMTP activity, run sudo grep "lmtp" /var/log/maillog | tail -5. Look for entries like status=sent (250 2.0.0 OK) to confirm that the message was accepted.
Common Issues and Fixes
You may encounter some common problems during setup. These include errors such as ‘relay access denied’ or messages not appearing in the expected Maildir location even when logs show successful delivery. To resolve these issues:
Check your configuration for correct values in
virtual_mailbox_domainsandvirtual_mailbox_base.Make sure all Maildir folders have the right permissions and user mappings.
Careful review of your settings and file ownership helps you avoid most delivery problems.
Optional Enhancements (Sieve, Quota)
You can add features to improve your mail system. Sieve lets you automate actions like sorting messages or sending vacation replies. Users can manage filters through a webmail interface, such as Roundcube, which makes organization simple and does not require advanced technical skills. Quota management allows you to set mailbox size limits for users. You can enable or disable quotas based on your needs.
Tip: Adding Sieve and quota support gives your users more control and helps you manage resources efficiently.
You can set up LMTP delivery to Maildir virtual users by following these steps:
Create virtual users with system accounts or a virtual user database.
Set permissions for mailbox access.
Update virtual mailbox maps to match each email address.
Dovecot LMTP with Postfix gives you reliable and secure email delivery. Always test your setup and review logs for errors. For advanced security, explore these topics:
Enforce SMTP AUTH and Multi-Factor Authentication.
Use content filtering and enable TLS encryption.
Monitor logs and update your mail server software regularly.
FAQ
How do you check if LMTP delivery works?
You can send a test email to a virtual user. Check the Maildir folder for new messages. Review the Dovecot and Postfix logs for delivery status. Look for “status=sent” or “OK” messages.
What should you do if emails do not appear in Maildir?
First, verify mailbox permissions and ownership. Make sure your mapping files are correct. Restart Dovecot and Postfix. Check log files for errors. Fix any configuration mistakes you find.
Can you use LMTP with SSL encryption?
Yes, you can enable SSL for LMTP. Set up SSL certificates in Dovecot. Update your configuration files to use secure connections. This protects your email data during delivery.
How do you add new virtual users?
Add the user to your virtual mailbox maps. Create a Maildir folder for the new user. Set the correct ownership and permissions. Update the mapping database with postmap. Reload Postfix and Dovecot.

