Disable default Email address for all accounts?

Aug 22, 2008
15
0
51
Hey there. I apologize if this has already been answered but I couldn't find it. Does anyone know how to disable default email addresses for all accounts on WHM 11.30.0.?
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
The default email address will always exist on cPanel at this time, but you can change the behavior for the default address to not have emails go to it directly on account creation. This would be done in WHM > Tweak Settings > Initial default/catch-all forwarder destination area. You could change it to "Fail" rather than the "System account default" selection, then click the "Save" button there.

I also did a post recently on how to change the accounts that previously had it set to the default at this location:

http://forums.cpanel.net/f43/root-email-advise-208742.html#post857372
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator

kitsguru

Member
Apr 30, 2011
10
0
51
I agree that the default email address based on the account name is a problem for all the reason stated above. I support the move to change this behaviour of cPanel.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
I agree that the default email address based on the account name is a problem for all the reason stated above. I support the move to change this behaviour of cPanel.
My previous reply:

There is not a way to hide this address, but you are welcome to lend support to the existing feature request to have this default cPanel username address removed:

http://forums.cpanel.net/f43/f145/case-4...in-134421.html
Have you posted on the feature request thread that I indicated? I do not see a post there on any of the 3 pages of the request. I would be very happy to move your post to that thread if you would like.

Of note, in the meantime, I am working on how to disable the address from showing up and working. Once I have the script completed on how to get it disabled, I will post it here as a guide; however, posting in this thread will not lend support to the feature request itself, so you would need to post your support there for that functionality.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
I have the steps you can use to disable the default address working and showing up in cPanel until such a feature has been implemented.

First of all, do the following in WHM > Packages > Feature Manager, select the disabled list there (if it does not exist, in root SSH go to /var/cpanel/features and create the file disabled).

In that disabled feature list, select Default Address Manager and uncheck it, then click "Save"

The Default Address option will no longer appear in cPanel on accounts. Additionally, the default email address will not show up in cPanel > Email Accounts area.

Next, go to WHM > Tweak Settings > Initial default/catch-all forwarder destination, then change that from "System account default" to "fail" and click the "Save" button at the bottom. This will ensure all new accounts have no default address set for non-existing email address, so those addresses will fail.

Now, to replace any users who previously had it set to their cPanel username default address, do the following:

Code:
cp -R /etc/valiases /etc/valiases.bak110630
for i in `ls /var/cpanel/users/`;do replace "*: $i" "*: :fail: No Such User Here" -- /etc/valiases/*;done
This will replace their username in those files with *: :fail: No Such User Here instead.

Next, create the following file to disable [email protected] working:

Code:
touch /etc/discarddefaultfilter
chmod +x /etc/discarddefaultfilter
The following content would be put into that file and should only be run once when first setting this up:

Code:
#!/bin/sh
#Send [email protected] emails to /dev/null filter script
#This writes to /etc/vfilters/ files for each main domain
#This also creates /home/username/.cpanel/filter.yaml files for each account

export HOSTNAME=`hostname`
while read x ; do
    xUSER=`echo $x | cut -d : -f 2 | awk '{print $1}'`
    xDOMAIN=`echo $x | cut -d : -f 1`

    echo >> /etc/vfilters/$xDOMAIN
    echo 'if not first_delivery and error_message then finish endif' >> /etc/vfilters/$xDOMAIN
    echo 'if' >> /etc/vfilters/$xDOMAIN
    echo "\$header_to: is \"[email protected]$HOSTNAME\"" >> /etc/vfilters/$xDOMAIN
    echo 'then' >> /etc/vfilters/$xDOMAIN
    echo 'save "/dev/null" 660' >> /etc/vfilters/$xDOMAIN
    echo 'endif' >> /etc/vfilters/$xDOMAIN
done < /etc/trueuserdomains

for i in `ls /var/cpanel/users/`;
do echo "---
filter:
  -
    actions:
      -
        action: save
        dest: /dev/null
    filtername: default discard
    rules:
      -
        match: is
        opt: or
        part: \"$(printf '$header_to:')\"
        val: [email protected]$HOSTNAME
    unescaped: 1" >> /home/$i/.cpanel/filter.yaml;
done

for i in `ls /var/cpanel/users/`; do chown $i:$i /home/$i/.cpanel/filter.yaml; done
You would then run the script:

Code:
/etc/defaultfilterscript
Thanks go to Jeff P at cPanel for the first portion of the script.

I will need to check further into how this can be accomplished on new account creation so that you have a postwwwacct script to add these entries for a new account that is created.
 

JugglesXP

Registered
Jul 25, 2011
2
0
51
I have the steps you can use to disable the default address working and showing up in cPanel until such a feature has been implemented.

First of all, do the following in WHM > Packages > Feature Manager, select the disabled list there (if it does not exist, in root SSH go to /var/cpanel/features and create the file disabled).

In that disabled feature list, select Default Address Manager and uncheck it, then click "Save"

The Default Address option will no longer appear in cPanel on accounts. Additionally, the default email address will not show up in cPanel > Email Accounts area.

Next, go to WHM > Tweak Settings > Initial default/catch-all forwarder destination, then change that from "System account default" to "fail" and click the "Save" button at the bottom. This will ensure all new accounts have no default address set for non-existing email address, so those addresses will fail.

Now, to replace any users who previously had it set to their cPanel username default address, do the following:

Code:
cp -R /etc/valiases /etc/valiases.bak110630
for i in `ls /var/cpanel/users/`;do replace "*: $i" "*: :fail: No Such User Here" -- /etc/valiases/*;done
This will replace their username in those files with *: :fail: No Such User Here instead.

Next, create the following file to disable [email protected] working:

Code:
touch /etc/discarddefaultfilter
chmod +x /etc/discarddefaultfilter
The following content would be put into that file and should only be run once when first setting this up:

Code:
#!/bin/sh
#Send [email protected] emails to /dev/null filter script
#This writes to /etc/vfilters/ files for each main domain
#This also creates /home/username/.cpanel/filter.yaml files for each account

export HOSTNAME=`hostname`
while read x ; do
    xUSER=`echo $x | cut -d : -f 2 | awk '{print $1}'`
    xDOMAIN=`echo $x | cut -d : -f 1`

    echo >> /etc/vfilters/$xDOMAIN
    echo 'if not first_delivery and error_message then finish endif' >> /etc/vfilters/$xDOMAIN
    echo 'if' >> /etc/vfilters/$xDOMAIN
    echo "\$header_to: is \"[email protected]$HOSTNAME\"" >> /etc/vfilters/$xDOMAIN
    echo 'then' >> /etc/vfilters/$xDOMAIN
    echo 'save "/dev/null" 660' >> /etc/vfilters/$xDOMAIN
    echo 'endif' >> /etc/vfilters/$xDOMAIN
done < /etc/trueuserdomains

for i in `ls /var/cpanel/users/`;
do echo "---
filter:
  -
    actions:
      -
        action: save
        dest: /dev/null
    filtername: default discard
    rules:
      -
        match: is
        opt: or
        part: \"$(printf '$header_to:')\"
        val: [email protected]$HOSTNAME
    unescaped: 1" >> /home/$i/.cpanel/filter.yaml;
done

for i in `ls /var/cpanel/users/`; do chown $i:$i /home/$i/.cpanel/filter.yaml; done
You would then run the script:

Code:
/etc/defaultfilterscript
Thanks go to Jeff P at cPanel for the first portion of the script.

I will need to check further into how this can be accomplished on new account creation so that you have a postwwwacct script to add these entries for a new account that is created.

2 Things:

should the execute code read
Code:
/etc/discarddefaultfilter
??

if so, it fails: bash: /etc/discarddefaultfilter: /bin/sh^M: bad interpreter: No such file or directory
 

tomdchi

Well-Known Member
Feb 24, 2008
140
3
68
Atlanta, GA
cPanel Access Level
DataCenter Provider
After running this script I am getting a lot of mail stuck in the queue. When I try to run the queue I get the error:

Code:
R=central_filter defer (-17): error in redirect file: missing or malformed local part (expected word or "<") in "if not first_delivery and error_message then finish endif"
How can I fix this?
 

JZM

Member
Aug 17, 2007
19
0
51
I got the following:


/etc/discarddefaultfilter: line 5: account: command not found
/etc/discarddefaultfilter: line 13: syntax error near unexpected token `newline'
/etc/discarddefaultfilter: line 13: ` echo 'if not first_delivery and error_message then finish endif' >> '


WHM 11.32.2 (build 15)
 

madsere

Well-Known Member
Apr 7, 2004
49
3
158
cPanel Access Level
DataCenter Provider
Code:
for i in `ls /var/cpanel/users/`;do replace "*: $i" "*: :fail: No Such User Here" -- /etc/valiases/*;done
I had a lot of trouble with this code snip, specifically the 'replace' command. It kept throwing some arbitrary error 122 about not being able to rename files ... I use a simple piece of perl regex (that ran a ton faster anyway.)

Code:
for i in `ls /var/cpanel/users/`; do perl -pi -e "s/\*: $i/\*: :fail: No Such User Here/i" /etc/valiases/*; done
Anyway why not just make this a tickbox on the tweak page so that the admin can tick "convert existing redirects as well". It can't be that hard to do.
 
Last edited:

Smaily

Well-Known Member
Sep 19, 2011
46
0
56
cPanel Access Level
Root Administrator
cPanelTristan guide ruined my mail delivery. All mails stayed in queue and did not come in nor gone out with error message,

Deliver Email
LOG: MAIN
cwd=/usr/local/cpanel/whostmgr/docroot 6 args: exim -C /etc/exim_outgoing.conf -v -M 1VCpS2-0006Je-Tp
delivering 1VCpS2-0006Je-Tp
LOG: MAIN
== [email protected] R=central_filter defer (-17): error in redirect file: missing or malformed local part (expected word or "<") in "if not first_delivery and error_message then finish endif"
Issue seemed to be in /etc/vfilters

Domains that were stuck in queue had following content in,

if not first_delivery and error_message then finish endif
if
$header_to: is "[email protected]"
then
save "/dev/null" 660
endif
Case closed with solution,

cd /etc/vfilters
truncate -s 0 *.*

I personally suggest to delete this thread as it malfunctioned my customers e-mails for hour-two. No clue what it might do in other people servers and kernels.