As a general policy at CharlesWorks, we set up email on separate servers from your website. Doing this keeps mail server traffic from affecting website resources and vice versa. The local mail server on the DirectAdmin must be disabled when using a remote mail server. Failure to do so can allow unsent messages, notifications and form outputs to accumulate on the web server.
DirectAdmin servers default to using local email. When mail is handled remotely for domains, issues arise when one forgets to disable the local mail. We can disable the local mail server in DirectAdmin by default with the help of a domain_create_post.sh script. This article presumes you are able to log onto the DirectAdmin server at a command prompt as the root user.
Creating the script
Our first step is to create the /usr/local/directadmin/scripts/custom/domain_create_post.sh script using your favorite text editor. I use Nano, which just happens to be my favorite Linux text editor. I always install it on my Linux based systems if it isn’t already there. The script could even be created in any text editor on your desktop and uploaded to the correct area via FTP if you like.
Most importantly, the script must be in a specific location on the server and named correctly in order for DirectAdmin to automatically execute it when a new domain is added to the server.
Bearing that placement is important to successfully implementing the script, let’s navigate to the correct directory first using the cd (change directory) command. This command will navigate us to the correct directory in which our file needs to be:
Now we can open Nano (or whichever text editor you are using) and create the file that will become our script on the server if it doesn’t already exist:
Then, once in the text editor you will need to add the following lines of code in it:
#!/bin/sh FILE=/etc/virtual/domains cp -f $FILE $FILE.backup grep -v -e "^$domain\$" $FILE > $FILE.tmp mv -f $FILE.tmp $FILE chmod 644 $FILE chown mail:mail $FILE exit 0;
Now you can save the script and exit your text editor. If you used Nano, that can be accomplished with:
- CTRL O to write the file out to the disk
- pressing ENTER to verify you want to write it
- CTRL X to exit back to your command line
You’re not done yet, though!
Fixing the script ownership
The file you just created and saved belongs to root. You can execute the chown (change ownership) command on the script to change it to diradmin:diradmin to avoid permissions problems later. This can be accomplished using this command:
chown diradmin:diradmin domain_create_post.sh
Making the script executable
You next need to execute the chmod (change mode) command on the script to change it to 755 so it is executable. This can be accomplished using this command:
chmod 755 domain_create_post.sh
Now any newly created domains should not be in the /etc/virtual/domains file. This means mail for each newly created domain going forward will default to being handled on a remote mail server rather in the local DirectAdmin account.
Mail and other MX settings
This part is important if you are using the DirectAdmin server your site is on as its DNS server. Otherwise it will not matter. As a general policy at CharlesWorks, as well as email, we set up DNS on separate servers from your website. Again, doing this keeps web server traffic from being affected by other services that can affect website resources and vice versa.
If your DNS is in fact being handled by your DirectAdmin website server, then one way to handle your mail and MX records is to copy the /usr/local/directadmin/data/templates/dns_mx.conf file to a custom folder in the same directory and then edit the custom/dns_mx.conf for the correct default values.
The other way is to simply edit the appropriate DNS records in the DirectAdmin domain manager interface. If it appears you do not have the MX Records menu in your DirectAdmin User Level login, then you should ask CharlesWorks (or your hosting provider) to enable the DNS Control option for your account.