Child pages
  • cPanel API 2 Functions - Email::addforward

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Excerpt

This function creates an email forwarder.


Warning
titleWarning:

We strongly recommend that you use the following UAPI function instead of this function:

  • Email::add_forwarder

    Excerpt Include
    DD:UAPI Functions - Email::add_forwarder
    DD:UAPI Functions - Email::add_forwarder
    nopaneltrue

Multiexcerpt include
SpaceWithExcerptcom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@12665
MultiExcerptNameAPIDisabledReceiveSendMailRoles
PageWithExcerptLIB:_ServerRoleDisabledAPI

Panel
bgColor#F2F2F2
borderStylenone

Examples 


Panel
bgColor#FFFFFF
borderStylenone


Expand
titleWHM API (JSON)


Code Block
languagetext
https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addforward&domain="example.com"&email="forwardme@example.com"&fwdopt="fwd"&fwdemail="fwdtome@example.com"

Include Page
LIB:_CallFromWHMAPILink
LIB:_CallFromWHMAPILink


Expand
titleLiveAPI PHP Class


Code Block
languagephp
linenumberstrue
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Forward mail from forwardme@example.com to fwdtome@example.com
$add_mail_forwarder = $cpanel->api2(
    'Email', 'addforward', 
    array(
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'fwd',
        'fwdemail'        => 'fwdtome@example.com',
    ) 
);
 
// Bounce mail to forwardme@example.com with a message.
$add_mail_forwarder = $cpanel->api2(
    'Email', 'addforward', 
    array(
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'fail',
        'failmsgs'        => 'Nobody's home.',
    ) 
);
// Delete mail that forwardme@example.com receives.
$add_mail_forwarder = $cpanel->api2(
    'Email', 'addforward', 
    array(
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'blackhole',
    ) 
);
 
// Pipe forwardme@example.com's mail to script.pl
$add_mail_forwarder = $cpanel->api2(
    'Email', 'addforward', 
    array(
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'pipe',
        'pipefwd'         => 'script.pl',
    ) 
);
 
// Forward forwardme@example.com's mail to a system account.
$add_mail_forwarder = $cpanel->api2(
    'Email', 'addforward', 
    array(
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'system',
        'fwdsystem'       => 'user',
    ) 
);

Include Page
LIB:_LiveAPIPHPLink
LIB:_LiveAPIPHPLink

 


Expand
titleLiveAPI Perl Module


Code Block
languageperl
linenumberstrue
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Forward mail from forwardme@example.com to fwdtome@example.com
my $add_mail_forwarder = $cpliveapi->api2(
    'Email', 'addforward',
    { 
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'fwd',
        'fwdemail'        => 'fwdtome@example.com',
    }
);
 
 
# Bounce mail to forwardme@example.com with a message.
my $add_mail_forwarder = $cpliveapi->api2(
    'Email', 'addforward',
    { 
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'fail',
        'failmsgs'        => 'Nobody's home.',
    }
);



# Delete mail that forwardme@example.com receives.
my $add_mail_forwarder = $cpliveapi->api2(
    'Email', 'addforward',
    { 
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'blackhole',
    }
);


 
# Pipe forwardme@example.com's mail to script.pl
my $add_mail_forwarder = $cpliveapi->api2(
    'Email', 'addforward',
    { 
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'pipe',
        'pipefwd'         => 'script.pl',
    }
);


# Forward forwardme@example.com's mail to a system account.
my $add_mail_forwarder = $cpliveapi->api2(
    'Email', 'addforward',
    { 
        'domain'          => 'example.com',
        'email'           => 'forwardme@example.com',
        'fwdopt'          => 'system',
        'fwdsystem'       => 'user',
    }
);

Include Page
LIB:_LiveAPIPerlLink
LIB:_LiveAPIPerlLink

 


Expand
titlecPanel Tag System (deprecated)

Include Page
LIB:_cPanelAPI2cPanelTagsWarning
LIB:_cPanelAPI2cPanelTagsWarning


Expand
titleCommand Line


Code Block
languagebash
cpapi2 --user=username Email addforward domain=example.com email=forwardme%40example.com fwdopt=fwd fwdemail=fwdtome%40example.com


Note
titleNote:

For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.  



Expand
titleOutput (JSON)


Code Block
languagetext
linenumberstrue
{
  "cpanelresult": {
    "apiversion": 2,
    "func": "addforward",
    "data": [
      {
        "email": "forwardme@example.com",
        "domain": "example.com",
        "forward": "fwdtome@example.com"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "Email"
  }
}


Include Page
LIB:_cPanelAPIShellNote
LIB:_cPanelAPIShellNote


Parameters

ParameterTypeDescriptionPossible valuesExample
domainstring

Required

The domain.

A valid domain on the account.

example.com
emailstring

Required

The email address to forward.

An email address on the account.

Note
titleNote:

You can pass multiple addresses to this parameter as a comma-separated list. 


forwardme@example.com
fwdoptstring

Required

The method to use to handle the email address's mail.

  • fwd — Forward messages to the fwdemail parameter's address.
  • fail — Bounce messages back to the sender, and include the failmsgs parameter's failure message.
  • blackhole — Send messages to the /dev/null/ directory. This method does not generate a failure notice.
  • pipe — Pipe mail to the pipefwd parameter's application.
  • system — Forward messages to the fwdsystem system account.
fwd
fwdemailstring

The email address to which the system forwards messages.

Note
titleNote:

Use this parameter if you used the fwd method for the fwdopt parameter. 


A valid email address.fwdtome@example.com
fwdsystemstring

The system user to whom the system forwards messages.

Note
titleNote:

Use this parameter if you used the system method for the fwdopt parameter. 


An account on the system.user
failmsgsstring

The failure message for the message's sender.

This parameter defaults to No such person at this address.

Note
titleNote:

Use this parameter if you used the fail method for the fwdopt parameter. 


A valid string. Nobody's home.
pipefwdstring

The application to which the system pipes messages.

Note
titleNote:

Use this parameter if you used the pipe method for the fwdopt parameter. 


The location of a program or script, relative to the account's home directory. mailscript.pl

Returns

ReturnTypeDescriptionPossible valuesExample
domainstring

The domain.

A valid domain on the account.

example.com
emailstringThe email address.An email address on the account.forwardme@example.com
forwardstringThe method that the system will use to handle the address's email.
  • An email address — The system forwards mail to this address.
  • :fail: — The system bounces mail back to the sender, and sends a failure message.
  • :blackhole: — The system deletes mail without a failure message.
  • The path to an application — The system pipes mail to this application.
  • A username — The system forwards mail to this system account.
forwardtome@example.com
reasonstring

A reason for failure.

Note
titleNote:

This function only returns a reason value if it failed. 


A string that describes the error.

This is an error message.
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1