The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Disable default Email address for all accounts?

Discussion in 'E-mail Discussions' started by Tyler Jacobson, Jun 21, 2011.

  1. Tyler Jacobson

    Joined:
    Aug 22, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    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.?
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    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
     
  3. Tyler Jacobson

    Joined:
    Aug 22, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Thanks. Is there a way to hide this Default Address from the cPanel under Email accounts?
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
  5. kitsguru

    kitsguru Member

    Joined:
    Apr 30, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    My previous reply:

    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.
     
  7. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    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 username@hostname 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 username@hostname 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 \"$xUSER@$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: $i@$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.
     
  8. JugglesXP

    JugglesXP Registered

    Joined:
    Jul 25, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1

    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
     
  9. JugglesXP

    JugglesXP Registered

    Joined:
    Jul 25, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    OK.. fixed the fail: it needed to be saved as unix end of line charachters
     
  10. tomdchi

    tomdchi Well-Known Member

    Joined:
    Feb 24, 2008
    Messages:
    116
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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?
     
  11. JZM

    JZM Member

    Joined:
    Aug 17, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    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)
     
  12. madsere

    madsere Well-Known Member

    Joined:
    Apr 7, 2004
    Messages:
    49
    Likes Received:
    2
    Trophy Points:
    8
    cPanel Access Level:
    DataCenter Provider
    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.
     
    #12 madsere, Jun 14, 2013
    Last edited: Jun 14, 2013
  13. Smaily

    Smaily Well-Known Member

    Joined:
    Sep 19, 2011
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    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,

    Issue seemed to be in /etc/vfilters

    Domains that were stuck in queue had following content in,

    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.
     
Loading...

Share This Page