Adding specific forwarders by default


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Email

Adding specific forwarders by defaultLast Modified: Apr 18, 2016, 2:21 pm
If you wish for specific default forwarders be present for new domains, for example "postmaster", you can create the script:

/usr/local/directadmin/scripts/custom/domain_create_post.sh

and add the code

#!/bin/sh

#modify the TO value as desired
TO=${username}

ALIASES=/etc/virtual/${domain}/aliases
TEMP_ALIASES=${ALIASES}.temp

addalias()
{
   COUNT=`grep -c -e "^${1}:" ${ALIASES}`
   if [ "${COUNT}" -eq 0 ]; then
       echo "${1}: ${TO}" >> ${TEMP_ALIASES}
       cat ${ALIASES} >> ${TEMP_ALIASES}
       mv -f ${TEMP_ALIASES} ${ALIASES}
       chown mail:mail ${ALIASES}
   fi
}

addalias postmaster
addalias webmaster
addalias abuse

exit 0;

chmod the script to 755:

chmod 755 /usr/local/directadmin/scripts/custom/domain_create_post.sh

You can add more lines, in addition to the postmaster entry to add more aliases by default.




If you wish to apply this to existing domains, you can create the script

/root/fix.sh

and add the code:

#!/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
   {
       domain=$d username=$u /usr/local/directadmin/scripts/custom/domain_create_post.sh
   };
   done;
};
done;
exit 0;

chmod the fix.sh to 755 as well, then run it:

cd /root
chmod 755 fix.sh
./fix.sh

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST