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.

Create forwarder on non-existing email address

Discussion in 'cPanel Developers' started by tizoo, May 29, 2015.

  1. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi all,

    We noted that on new release of cPanel, it is no more possible to create a forwarder on an email address that doesn't exist on the system. This was possible before, but I don't remember exactly when (11.46, 11.48.2... ?).

    We have a plugin that let our customers define business level email addresses on a Zimbra server through their cpanel interface.

    The previous working mode of cPanel tool to define forwarder was perfect to also define forwarders on the addresses on the Zimbra as I guess it didn't check the existing of the email address on the local cPanel server.

    Is there a configuration option to disable this check ?

    We started trying to hook on Api2::Email::addforwad but it doesn't seems that we can modify the behavior event with a *pre* hook that will return *true*.

    We thought about updating the /etc/valiases/[domain] file with our hook, but the error will anyway be displayed, right ?

    Is it the right way to do it ? Does someone have a better solution ?

    Thanks a lot for any tips,

    Cheers,
    Philippe
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    This is by design, as it should produce the following error message:

    It's not possible to disable this functionality, but you could setup a hook that automatically creates the local email account before creating the forwarder.

    Thank you.
     
  3. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi cPanelMichael,

    Thank you for your response.

    I also thought about your solution, that is to say creating the email address in a pre hook and deleting it on a post hook. But as this seemed to me a little bit *killing a fly with a shotgun* I was wondering if there was not a more simple solution. Regarding your response it seems that it's not the case.

    Thanks for this information that let us go forward.

    Cheers,
    Philippe
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    One other solution is to insert filter rules for the account that redirect email if the recipient matches a specific address.

    Thank you.
     
  5. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi cPanelMchael,

    The solution using filter rules is not an option as it change the customer approach.

    Our plugin let customers to define business level mailboxes on a Zimbra server through their cPanel interface. They could also define classic mailboxes directly on the cPanel server. As the idea is to managed everything from cPanel interface, when they define a forwarder on a mailbox defined on the Zimbra server, the behavior should be the same as if the mailbox was a classic one defined on the cPanel server.

    We will use the approach of create mailbox, create forwarder, delete mailbox which seems the only one that should work.

    Thanks for your support and idea.

    Cheers,
    Philippe
     
  6. shoutandecho

    shoutandecho Registered

    Joined:
    Feb 16, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Why is this by design? I'm having lots of problems with the new cPanel version, and this is another one. I have domains assigned to my system for which i just host websites (another company points their A records to my IP address). Before this new cPanel release, if i wanted to forward email from my server to an email account on one of the domains assigned to my server, i could so without problems. Everyone was happy. Now i get the error mentioned above.

    Example: i am hosting a site for domain1.com. They are pointing their A record to my IP. No email hosted by me, and their MX records are pointed to a separate mail server. Before, i could forward email from my server to emailaddress@domain1.com. Now i get the error.
     
  7. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi cPanelMichael,

    I tried to make it work (create the email in the pre hook and delete it in the post hook) but I'm stuck on understanding how everything works.

    I know that the hook is executed as the user creating the forwarder, then thus the user is logged (it execute the hook) how could I make it execute the creation of the email (and then the deletion of it after sucessfully created the forwarder) ?

    I guess I missed something as in all the documentation and the code/example I have read, there is always necessary to do an authenticated connexion when using a cPanel API. But in the hook, the user is already connected, I should then have access to some more simple connection/API call. And I anyway cannot connect with the user as I don't have its password...

    What did I missed ?
    Is there a way to solve this ?

    Thanks a lot in advance for any tips.

    Cheers,
    Philippe


     
  8. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi cPanelMichael,

    I finally found how to make it works.

    If this is usefull for someone, here is our code to let users creating a forwarder on an external email (an external Zimbra server in our case) whose domain is however defined on the cPanel server :

    Code:
    #!/usr/bin/perl
    package TZbm::WHM;
    
    use strict;
    use warnings;
    
    use Cpanel::XML;
    use Data::Dumper;
    use XML::Simple;
    use Cpanel::Logger;
    
    # Instantiate the cPanel logging object.
    my $logger = Cpanel::Logger->new();
    
    sub describe {
        my $tzbm_hooks = [
            {
                'category' => 'Cpanel',
                'event'    => 'UAPI::Email::add_forwarder',
                'stage'    => 'pre',
                'hook'     => 'TZbm::WHM::preAddForwarder',
                'exectype' => 'module',
            },
            {
                'category' => 'Cpanel',
                'event'    => 'UAPI::Email::add_forwarder',
                'stage'    => 'post',
                'hook'     => 'TZbm::WHM::postAddForwarder',
                'exectype' => 'module',
            }
        ];
        return $tzbm_hooks;
    }
    
    sub preAddForwarder {
        my ($context, $data) = @_;
        my $result = 1;
        my $message = "Forwarder created";
    
        # Simulate existence of the email
        my ($user, $domain) = split(/@/, $data->{'args'}{'fwdemail'});
    
        my $args = {
            'cpanel_xmlapi_module'     => 'Email',
            'cpanel_xmlapi_func'       => 'addpop',
            'cpanel_xmlapi_apiversion' => '2',
            'cpanel_xmlapi_user'       => $data->{'user'},
            'domain'                   => $domain,
            'email'                    => $user,
            'password'                 => '[somepass...]'
        };
        my $xml = Cpanel::XML::cpanel_exec_fast($args);
        my $xmlRef = XML::Simple::XMLin($xml);
        $logger->info(Data::Dumper::Dumper($xmlRef));
        return ($result, $message);
    }
    
    sub postAddForwarder {
        my ($context, $data) = @_;
        my $result = 1;
        my $message = "Forwarder created on " . $data->{'args'}{'fwdemail'};
    
        # Remove the email
        my ($user, $domain) = split(/@/, $data->{'args'}{'fwdemail'});
    
        my $args = {
            'cpanel_xmlapi_module'     => 'Email',
            'cpanel_xmlapi_func'       => 'delpop',
            'cpanel_xmlapi_apiversion' => '2',
            'cpanel_xmlapi_user'       => $data->{'user'},
            'domain'                   => $domain,
            'email'                    => $user
        };
        my $xml = Cpanel::XML::cpanel_exec_fast($args);
        my $xmlRef = XML::Simple::XMLin($xml);
        $logger->info(Data::Dumper::Dumper($xmlRef));
        return ($result, $message);
    }
    
    1;
    
    Hope this helps and thank you for your tips,

    Philippe
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Email accounts or email forwarders would not function for a domain name that has it's email hosted on a remote server. For instance, if addon-domain.tld is added to your cPanel account, but it's email is handled by a remote server, then any email accounts or forwarders you create for addon-domain.tld would not function because the domain name's email is not handled on the cPanel server.

    I'm happy to see you were able to find a suitable workaround. Thank you for updating us with the outcome.
     
Loading...

Share This Page