Virtual Users And Domains With Sendmail

sendmailThe objective of this guide is to enable Sendmail’s virtual user table, which allows us to configure user-specific and domain-wide email aliases for multiple domains. These instructions assume you are using a CentOS virtual server.

Sendmail uses a highly complex rule system for it’s configuration so instead of editing sendmail.cf directly, we will edit the sendmail.mc file.

Accepting mail for virtual domains/users

1.Create a new system user and set the password for that user.

useradd exampleuser
passwd exampleuser

2. Add the user to the sendmail’s virtusertable file. Open the ‘/etc/mail/virtusertable’ file and add the following:

exampleuser@exampledomain.tld    exampleuser

Each line in the /etc/mail/virtusertable file should be of the following format:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
username@domainname    systemuser

3. Add each new domain name to the /etc/mail/local-host-names file

exampledomain.tld

4. Generate a new sendmail.cf file by using the following commands:

cd /etc/mail
make all
/etc/init.d/sendmail restart

Rewriting outgoing email addresses

1. Add the following lines to the /etc/mail/sendmail.mc file:

FEATURE(masquerade_envelope)
FEATURE(genericstable, `hash -o /etc/mail/genericstable')
GENERICS_DOMAIN_FILE(`/etc/mail/sendmail.gdf')

2. Create /etc/mail/genericstable file containing local users mapped to desired addresses:

exampleuser    exampleuser@exampledomain.tld
exampleuser2    exampleuser2@exampledomain.tld

3. Create /etc/mail/sendmail.gdf file containing the fully qualified name of the local mail server.

host.exampledomain.tld

4. Finally, generate a new sendmail.cf file:

cd /etc/mail
make all
/etc/init.d/sendmail restart

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “Virtual Users And Domains With Sendmail”

  1. Hi, thank you very much, for this tutorial.

    but i configured sendmail with dovecot in CentOS6, but system user not login in, some dovecot authentication problem. Please help

    Thanks,
    Ashwin Pandey

    Reply

Leave a Comment