Why is there a system email account?

For all domains created in DirectAdmin, you'll notice that there is always an email account with your DA username which cannot be deleted. This is the system email account associated with your DA login. It will always exist on the system as long as you have an account on the system. The value shown as an email in DA is actually a forwarder for username@domain.com to username@server.hostname.com, where username is your DA login and the server.hostname.com is the hostname of your server.

All domains created under "username" will have their email forwarded to the username@server.hostname.com email account. For any email client, the login format is just "username", without any @domain.com or @server.hostname.com at the end. It cannot be removed because this is where all emails for system tasks like cronjobs, cgi-bin scripts, suphp email replies, etc. will end up. Deleting it would cause bounces everywhere and hide the fact that emails are piling up in the account, invisible to the User.

Note that if you do not wish to actually receive emails to username@domain.com, you can go to: User Level -> Forwarders

and set:

username    ->   :fail:
1

where :fail: will reject all emails sent to it, as if it didn't exist. You can alternatively use :blackhole: instead of :fail: to drop/ignore all emails without creating a bounce/rejection.

It's very important to note that creating a blocked fail/blackhole forwarder for your username@domain.com account does not delete the system account. As mentioned, it cannot be deleted. The username@server.hostname.com account will still exist, and will still get emails from cronjobs or any system account process running as "username".

How to purge the Maildir inbox for all system accounts?

If you're noticing that your Users' System Accounts are not being checked often enough (or ever) and you wish to purge them, you can use the following script:

#!/bin/sh

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       for file in `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`; do
       {
               rm -fv $file;
       };
       done;
};
done;
exit 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Save the script, chmod to 755, and run.

This script needs to be run as root.

You can run this script as often as you wish with a cronjob to keep the system accounts trimmed.

Keep in mind that if you're deleting their data, Users may not appreciate this, so only run it if you're certain they're not checking this account.

How to disable system email account?

Since there will always be a system email account with any new DA User, sometimes Admins do not wish it to be active, as many clients simply don't know it's there or don't use it. It can then fill up with a lot of email, causing disk usage issues.

One solution is to disable the account for any domain created under that User. Note that the actual username@host.name.com value will still be active (can be disabled in /etc/aliases if you really want), but for the most part, disabling the alias username@domain.com -> username@host.name.com will be sufficient for most cases.

The username@domain.com is actually a forwarder to the hostname, so in this guide we're just going to disable that forwarder.

  1. Create the /usr/local/directadmin/scripts/custom/domain_create_post.sh script and add the code:
#!/bin/sh
STR="perl -pi -e 's#^$username:[ ]*$username\$#$username: :fail:#' /etc/virtual/$domain/aliases"
eval $STR;
exit 0;
1
2
3
4
  1. Chmod the script to 755:
chmod 755 /usr/local/directadmin/scripts/custom/domain_create_post.sh
1
  1. You can manually test the script and run it for existing accounts as follows:
cd /usr/local/directadmin/scripts/custom
username=fred domain=fredsdomain.com ./domain_create_post.sh
1
2
  1. Expanding on tip #3, you can run this for all existing accounts automatically with this script:
#!/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
      {
             username=$u domain=$d /usr/local/directadmin/scripts/custom/domain_create_post.sh
      };
      done;
};
done;
exit 0;
1
2
3
4
5
6
7
8
9
10
11
Last Updated: 6/23/2021, 9:36:08 PM