In the following tutorial, we will teach you how to configure Sendmail to use a virtual user table, which should allow us to set up user-specific, domain-wide email aliases with several domains on our server. This tutorial will work on other Linux VPS systems but was specifically tested and made for Ubuntu 16.04.
Configuring Sendmail to use our domains
Let’s start by verifying if the server is configured to accept mail for the domains we’d like to setup aliases for:
# cat /etc/mail/local-host-names test1.com test2.com
In this case, the domains we’d like to set up email aliases for are test1.com and test2.com. Ensure that you’ve got your domain’s MX records pointing to your VPS hostname before you set Sendmail to use them.
Now, in case the user we want to add an email alias to doesn’t exist on our server, we may create the user and give a password for the user by running the following commands:
# useradd testuser # passwd testuser
We can then configure sendmail to use the virtual user table by modifying sendmail.mc and by typing in the following lines:
# nano /etc/mail/sendmail.mc FEATURE(`virtusertable')dnl VIRTUSER_DOMAIN_FILE(`-o /etc/mail/virtuserdomain')dnl
Please ensure that those lines were indeed added before the MAILER() line, otherwise Sendmail is going to give back a warning/error on compilation. We will now compile the Sendmail configuration by entering in the following commands:
# make # sendmailconfig
The command sendmailmenuconfig is going to request from you that you answer a couple of questions, such as whether you would like to use the new configuration and reload it. Answer y(yes)/n(no) to all.
Creating the virtual user table and mapping users to our domains
Next, we will create the /etc/mail/virtuserdomain file by opening it with an editor, and we will then add the domains. Our choice of editor is going to be nano, because of its simplicity:
# nano /etc/mail/virtuserdomain test1.com test2.com
Let’s open the /etc/mail/virtusertable file and append the email aliases for our user:
# nano /etc/mail/virtusertable [email protected] testuser [email protected] [email protected]
Let’s explain what exactly happened here. We appended an email alias for testuser with the domain name test1.com and mapped it to the local mailbox of testuser, and we’ve also appended an email alias for testuser with the domain name test2.com and mapped it to a remote email address ([email protected]).
This is one of several options virtusertable offers. You could also map an entire domain name to an email address or local mailbox in the same way, but you would leave out the user portion of the first part of the address as such:
We can then close the file and execute the following commands:
@test1.com testuser @test2.com [email protected] We can then close the file and execute the following commands: # makemap hash virtusertable < virtusertable # /etc/init.d/sendmail reload Create outgoing email aliases
If we would like to create outgoing email addresses for our users, we have to modify the sendmail.cf file first and append the lines below into it:
FEATURE(masquerade_envelope) FEATURE(genericstable, `hash -o /etc/mail/genericstable') GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')
We will have to create the /etc/mail/genericstable file and modify it so it contains the local users which are going to be mapped to the desired addresses:
testuser [email protected] testuser2 [email protected]
We can now create the /etc/mail/generics-domains file, which has the FQDN (Fully Qualified Domain Name) of the local mail server:
mail.test1.com
Lastly, we will finish the process by generating new Sendmail configuration files by executing the following commands:
# make # sendmailconfig
Once more, answer yes to every question the sendmailconfig command asks you.
Remember to change the user and domain examples in the tutorial with your own.