How to set webmail server system in DirectAdmin panel

This article contains step by step on how to set webmail system for DirectAdmin users who have root access on their hosting.

This article works only for VPS, cloud, and dedicated hosting who have root access to their package with simple instruction.

Here we, let’s set up the webmail system in DirectAdmin,

  1. The domain and hostname used on the system should be different.
  2. We need to add the hostname in /etc/virtual/domains file.
  3. Do not add the hostname details in/etc/virtual/domainowners file.
  4. The hostname must resolve. If not, then we need to add the A record into the DNS zone such that the hostname resolves.
  5. The directory /etc/virtual/<hostname> must be available in the server without any files under that.
  6. We need to add the details of the domain, which is used by the mail system in both the /etc/virtual/domains file and the /etc/virtual/domainowners file. Furthermore, the system must have /etc/virtual/<domain> file, /etc/virtual/<domain>/passwd and /etc/virtual/<domain>/aliases files.
  7. File permission of the virtual pop inboxes should be set as below (excluding Dovecot/Maildir):
    /var/spool/virtual/<domain> 770 username:mail
    /var/spool/virtual/<domain>/* 660 username:mail 
  8. Ensure that the hostname is not having any uppercase letters.
  9. Ensure that the main server IP has set reverse lookup on it.

Here are the steps to rebuild /etc/virtual/domainowners file if it is empty;

Create a script under /etc/virtual folder with the name fix_domainowners.sh.

cd /etc/virtuals

vi fix_domainowners.sh

Press “i” to go into insert mode and update the below code into it.

#!/bin/sh
for u in `ls /usr/local/directadmin/data/users`; do
{
for d in `cat usr/local/directadmin/data/users/$u/domains.list`; do
{
echo “$d: $u”
for p in `cat /usr/local/directadmin/data/users/$u/domains/$d.pointers | cut -d= -f1 2>/dev/null`; do
{
echo “$p: $u”
}
done;
}
done;
}
done;

Exit insert mode (ctrl+c), then save and exit (click shift+Z twice) the file. Then run the below code in the command prompt:

chmod 755 fix_domainowners.sh
./fix_domainowners.sh > domainowners
chmod 644 domainowners
chown mail:mail domainowners

Done.