virtual users and domains on sendmail

Virtual Users and Domains with Sendmail on Ubuntu 16.04

Spread the love

In this tutorial, we will show you how to configure Sendmail to use a virtual user table that’ll allow us to set up user-specific, domain-wide email aliases with multiple domains on our server. This guide should work on other Linux VPS systems as well but was tested and written for  Ubuntu 16.04.

Configuring Sendmail to use our domains

Let’s begin by first checking if our server is configured to accept mail for the domains we want to set up aliases for:

# cat /etc/mail/local-host-names

In our case, the domains we want to set up email aliases for are and
Make sure you have your domain’s MX records pointing to your VPS hostname before you configure Sendmail to use them.

Now if the user we wish to add an email alias to doesn’t exist on our server, we can create the user and set a password for the user by typing in the following commands:

# useradd testuser
# passwd testuser

Then we configure Sendmail to use the virtual user table by editing and by entering in the following lines:

# nano /etc/mail/
VIRTUSER_DOMAIN_FILE(`-o /etc/mail/virtuserdomain')dnl

Make sure these lines are added before the MAILER() line, otherwise Sendmail will return a warning/error on compilation.

Next, we compile the Sendmail configuration by typing in the following commands:

# make
# sendmailconfig

The command sendmailmenuconfig will ask you a few questions whether you want to use the new configuration and reload it, answer y(or yes) on all.

Creating the virtual user table and mapping users to our domains

Now create the /etc/mail/virtuserdomain file by opening it with an editor and add your domains, our preferred editor is nano due to its simplicity:

# nano /etc/mail/virtuserdomain

Now let’s open the /etc/mail/virtusertable file and add the email aliases for our user:

# nano /etc/mail/virtusertable   testuser

Let me explain what we did here, we added an email alias for testuser using the domain name and mapped it to the local mailbox of testuser and we also added an email alias for testuser using the domain name and mapped it to a remote email address( These are some of the cool options virtusertable offers. You can also map an entire domain name to an email address or local mailbox the same way, except you would leave out the user portion of the first part of the address like this:   testuser

And then we close the file and enter the following commands:

# makemap hash virtusertable < virtusertable
# /etc/init.d/sendmail reload

Create outgoing email aliases

Now if we want to create outgoing email addresses for our users we need to edit the file first and add the following lines:

FEATURE(genericstable, `hash -o /etc/mail/genericstable')

Then we need to create the /etc/mail/genericstable file and edit it to contain our local users which will be mapped to the desired addresses:


And now we create the /etc/mail/generics-domains file containing the FQDN(fully qualified domain name) of the local mail server:

Finally, we will complete the procedure by generating new Sendmail configuration files with the following commands:

# make
# sendmailconfig

Again, answer yes to all the questions the sendmailconfig command asks you.
Note: Remember to replace the user and domain examples given in this tutorial with the names of your actual users and domains.

Of course, you don’t have to do any of this if you use one of our Service Configuration & Optimization Services, in which case you can simply ask our expert Linux admins to set up a mail server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, about Virtual Users and Domains with Sendmail on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a comment in the Comments Section below. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *