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.

block forwarding

Discussion in 'E-mail Discussions' started by Kailash1, Mar 24, 2009.

  1. Kailash1

    Kailash1 Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    252
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi,

    Is there a way I can setup global setting so that we can not set email forwarding to particular domain.

    For example, I do not want to allow email forwarder to @xyz.com from my server. Is it possible to block this for all the domains.

    Kailash
     
  2. Be Hard!

    Be Hard! Member

    Joined:
    Mar 24, 2009
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Well, if you want to stop email forwarding an easy wey is to remove the email forwarding feature from your package feature list.

    In that case the user wont be able to access to that option in cpanel. Also remember to set :fail: in all domains at /etc/valiases

    Cheers!

    Be Hard!
    Optimization & Security Services for Cpanel
     
  3. Kailash1

    Kailash1 Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    252
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    I don't want to remove email forwarding feature. I just don't want to allow forwarding to few domains i.e. block email forwarding to AOL, Comcast accounts.

    Kailash
     
  4. Rocko88

    Rocko88 Registered

    Joined:
    Apr 28, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    anwser?

    Hi,

    Yes, I would like to know the answer me too!
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    If you have a basic understanding of Perl, you can implement this at this time using Custom Event Handlers. This is different from the function hooks we talk about in that function hooks allow you to do additional things after an action has been performed. With Custom Event Handlers, you can create a "pre" handler that intercepts the call to Email::addforward and aborts it if certain conditions are met (e.g. the fwdemail parameter contains comcast.net).

    To implement a Custom Event Handler, create a new Perl Module called CustomEventHandler.pm in /usr/local/cpanel/Cpanel/ and create a subroutine called event in the module. You will also need to add this line of code to your event subroutine to pull in all the parameters being passed to it:

    Code:
    my ( $apiv, [COLOR="Red"]$type[/COLOR], [COLOR="RoyalBlue"]$module[/COLOR], [COLOR="SeaGreen"]$event[/COLOR], [COLOR="DarkOrchid"]$cfgref[/COLOR], $dataref ) = @_;
    As for what each of the parameters is:

    type is either pre or post. If the type is pre then that means this is before the event is happening. If the type is post, then the event has already happened

    module is the name of the module. This will be Cpanel:: followed by the module name from the API1 or API2 function being called. For example: Cpanel::Email

    event is the name of the function being called by API1 or API2. For example: addforward

    cfgref is a hash of the variables passed to the event. For example: $cfgref{'fwdemail'} would contain the email address to forward email to if email forwarding was the selected option.

    dataref is only used in post events. This simply contains the data returned from the event.


    Your event subroutine will be called every time an action is performed in the cPanel interface (both before and after). Actions are disallowed by returning false. Therefore, return true by default and only return false when you explicitly do not want something to happen. Otherwise, you may inadvertently disable all cPanel functionality.

    For example, you may want to have an if block where you see if the module is Cpanel::Email and the event is addforward and $cfgref{'fwdemail'} contains any of the domains you do not want mail forwarded to, and inside that block of code return false. If that if block is never executed, return true.

    Returning false on a pre event will prevent that event from happening. Returning false on a post event only prevents output from that event from being displayed.

    We plan to write up formal documentation on this. In the meantime, you can find some documentation in /usr/local/cpanel/hooks/README and the files it references. DO NOT EDIT EventHandler.pm! Instead, create your own CustomEventHandler.pm for your own event handling functions.

    I only recommend this if you are familiar with Perl as this can only be done in Perl. If you are not familiar with Perl, I recommend reading a book that can introduce you to the language so you become familiar with the syntax of Perl.
     
  6. Kailash1

    Kailash1 Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    252
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    Thanks David,

    I am not much familiar with Perl so I will not try this right now.

    Kailash
     
  7. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,384
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
  8. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,384
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    If you don't already have a CustomEventHandler.pm in /usr/local/cpanel/Cpanel try adding this attached file into that directory.

    Then create a file /etc/forwarder_blocked_domains.txt which contains the domain names of the forwarders you want to block from being created. One on each line.

    Example:
    Code:
    yahoo.com
    comcast.net
    Now when you try to create a forwarder that uses one of these domain names, you will get an error:

    The forwarder could not be added because the form was not complete or would create a mail loop.

    Not sure how to change that text, but it will prevent it from being created.

    I haven't really tested all of this, so use this at your own risk. If you have problems just delete the CustomEventHandler.pm file.

    Be sure that you place this file in the /usr/local/cpanel/Cpanel directory on your server. And be sure that you name the file CustomEventHandler.pm
     

    Attached Files:

  9. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Nice work Sparek.

    Hopefully this will provide some momentum to be inlcuded in cPanel by default.
     
  10. Rocko88

    Rocko88 Registered

    Joined:
    Apr 28, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    wow!!

    Oh wow! Thank you for the script! I'm verry glad!
     
  11. joehanz30

    joehanz30 Registered

    Joined:
    Jan 9, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Great scripts!!! btw, have any 1 tried this scripts? & is it working? :cool:
     
  12. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    It is for us.
     
  13. Kailash1

    Kailash1 Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    252
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi Sparek,

    Sorry for remain silent for few days. Thanks for the script.

    Kailash
     
  14. hploh

    hploh Member
    PartnerNOC

    Joined:
    Jun 14, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    Did any one got idea how to modify the error "
    The forwarder could not be added because the form was not complete or would create a mail loop."

    to other message such as forwarding to yahoo is not allowed, etc?

    Rgds
    Loh
     
  15. Janak

    Janak Well-Known Member

    Joined:
    Jul 18, 2009
    Messages:
    71
    Likes Received:
    1
    Trophy Points:
    6
    I think it is possible to modify message for Email Forwarding. There is similar kind of discussion in below thread

    zubrag.com/forum/index.php?topic=310.0
    Email forward creator script problem

    Janak
     
    #15 Janak, Apr 12, 2010
    Last edited by a moderator: Aug 7, 2015
  16. jenlepp

    jenlepp Well-Known Member

    Joined:
    Jul 4, 2005
    Messages:
    116
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Liberty Hill, TX
    cPanel Access Level:
    DataCenter Provider
    I modified it through WHM in the templates. Then it got overwritten.

    I gave up.
     
  17. kpmedia

    kpmedia Well-Known Member

    Joined:
    Feb 13, 2011
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    USA, Europe
    cPanel Access Level:
    Root Administrator
    This quit working. It was fine in x3, but Paper Lantern ignores it. :(

    Any ideas?
     
  18. youronlineva

    youronlineva Registered

    Joined:
    Aug 12, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    india
    cPanel Access Level:
    Website Owner
    I would prefer not to uproot email sending component. I simply would prefer not to permit sending to couple of spaces i.e. piece email sending to AOL, Comcast accounts.
     
  19. kpmedia

    kpmedia Well-Known Member

    Joined:
    Feb 13, 2011
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    USA, Europe
    cPanel Access Level:
    Root Administrator
    Before Paper Lantern ate it, that's what it was doing.
     
  20. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Custom event handlers are deprecated as documented at:

    Guide to Standardized Hooks - Custom Event Handlers

    The following post explains how to block outgoing email to specific domain names:

    https://forums.cpanel.net/threads/e...utgoing-mail-to-a-domain.361042/#post-1459812

    However, this is intended for all outgoing email and not for forwarders alone. I suggest reviewing the document referenced above for information on how to utilize hookable events.

    Thank you.
     
Loading...

Share This Page