Virtual users with LMTP in FreeBSD
In previous releases, e-mail addresses were only available to system users. This may or may not be a good idea depending on the scope of the e-mail system we are implementing, but what is certain is that implementing virtual users is practically essential.
With this premise we will make both OpenSMTPd and Dovecot integrate using LMTP together with a file that will contain the list of virtual users and their passwords.
Configuration
Create the user vmail
We need this user, who will be the one to store the mail of all virtual users.
And we give you the ownership of your directory $HOME.
Configure LMTP for OpenSMTPd
We need to install an OpenSMTPd extension that allows you to use the username and password file mentioned above.
Edit /usr/local/etc/mail/smtpd.conf
and include.
In addition to redirecting local which handles incoming mail to send it to LMTP which will use these files to check the validity of these virtual users as a destination.
And we also need to change the authentication to use the passwd file that we are going to use.
We are missing the alias for vmail by editing /etc/mail/aliases
.
Configure LMTP for Dovecot
Now it is Dovecot’s turn. We need a replica of the previous configurations, but to be used by Dovecot.
We change the authentication by editing /usr/local/etc/dovecot/conf.d/10-auth.conf
.
We change the user and password sources in /usr/local/etc/dovecot/conf.d/auth-passwdfile.conf.ext
.
Mail pickup at /usr/local/etc/dovecot/conf.d/10-mail.conf
.
Here a hierarchical structure will be generated inside /var/vmail
with the following structure.
Create virtual users
File /etc/mail/passwd
has the following format.
So we need to generate user passwords. To do so.
You will be silently prompted for the plain text password.
This last hash, in this case SHA512, is the one we will enter for the virtual user.
Finally, we need to map it to the vmail user so that the mail is delivered to his mailbox. We edit /etc/mail/virtuals
.
Restart the demons
Tests
Now we can configure our mail client and use these credentials to do some tests by sending and receiving emails with it.
Conclusions
Together with the other two entries already published, this one closes the core of the implementation of an email server. It is obvious that issues like securization, DKIM, DMARC, spam handling, greylisting, webmail, etc… are missing. This is already out of the basic functionality but I may address some of them in future posts.