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.

Prevent and restrict Outgoing email?

Discussion in 'E-mail Discussions' started by lowhigh, Dec 17, 2011.

  1. lowhigh

    lowhigh Active Member

    Joined:
    Jun 25, 2011
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    Hi everybody!

    My customer is so strict, he required us so much and I need your help!
    First, he want to monitor all incoming and outgoing from his email accounts. I easily have done this by following the guide to edit /etc/cpanel_exim_system_filter_custom
    Like this:
    Code:
    # Monitor both incoming and outgoing emails.
    if first_delivery
       and ("$h_to:, $h_cc:" contains "@domain.tld")
       or ("$h_from:" contains "@domain.tld")
       and ("$h_to:, $h_cc:, $h_from:" does not contain "monitor@")
    then
       unseen deliver "monitor@domain.tld"
    endif
    
    But now, he want to:
    - Prevent some email accounts from his domain sending outside but still sending locally
    - Restrict some other email accounts sending outside to some specific address such us only @gmail or @yahoo, other addresses is forbidden

    I find on Google some suggestes to disable Outgoing mail:
    Code:
    logfile /var/log/filter.log 0644
    if (
    $received_protocol is "local" or
    $received_protocol is "esmtpa"
    ) and (
    $header_from contains "@domain1.com" or
    $header_from contains "@domain2.com"
    )
    then
    save "/dev/null" 660
    endif
    
    But i really don’t know how to do, anybody has experienced can help me?

    Thanks so much!
     
  2. lowhigh

    lowhigh Active Member

    Joined:
    Jun 25, 2011
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    i'm not good at coding, anybody can help me!
     
  3. 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
    This appears to be a filter you would put for the account in /etc/vfilters/domain.com file for the domain. Please note you will also need to place a filter file at /home/username/.cpanel/filter.yaml location. Please replace domain.com with the actual domain name and username with the cPanel username in the paths noted.

    I highly suggest creating an example filter in cPanel > Account Level Filtering first so you can see what /etc/vfilters/domain.com and /home/username/.cpanel/filter.yaml look like so you can appropriately edit those files for the filter in question.
     
  4. lowhigh

    lowhigh Active Member

    Joined:
    Jun 25, 2011
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    Hi Tristan!

    I find that Filtering is usefull, so i understand:
    1.Account level Filtering is leaved for all email accounts and all domains under Cpanel acc
    2. User level Filtering is for specific account
    So, i choose User level Filtering
    Select my email account and Manage Filters
    My purpose is config my email account only sending locally within my domain.com and not sending outside

    I have created the filter
    Rules: Any recipent doesnot contain @mydomain.com
    Action: Fail with messages: Cannot sending outside

    And i see in the filter file is:
    Code:
    Exim filter
    
    # Auto Generated by cPanel.  Do not manually edit this file as your changes will be overwritten.  If you must edit this filter, edit the corresponding .yaml file as well.
    
    if not first_delivery and error_message then finish endif
    
    #Rule myaccount
    if
     foranyaddress $h_to:,$h_cc:,$h_bcc: ( $thisaddress does not contain "@mydomain.com" )
    then
     fail "Cannot sending outside"
    endif 
    
    Now,when i login webmail and create new mail, it still sending outside without any warning!
    Can you show me the incorrect config i have?
     
  5. 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
    You cannot create the type of filter you wanted to create using cPanel > User Level Filtering area. You must edit the filter file to use the protocols you want to allow or not allow that you provided previously.
     
  6. lowhigh

    lowhigh Active Member

    Joined:
    Jun 25, 2011
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    Hi Tristan!

    The content in the /etc/vfilter/domain.com has the same as in the filter file i have post.
    I don't know why the filter at user level and account level does not work
    Can U explain me and give me a example for my purpose!
     
  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
    You had an initial post with a different filter:

    Please revise the filter cPanel created as I only suggested using that filter to create an example that you would revise. I do not know the exact revision, since this is a customization. Your initial question was where to place that code and I indicated for cPanel > Account Level Filtering where to place the code. You've chosen to use cPanel > User Level Filtering instead and appear to have located the file you need to revise with the code you suggested using initially. Please feel free to test using that code you provided in your first post.
     
Loading...

Share This Page