cPanel API 2 Functions - Email::addforward
The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.
Description
This function creates an email forwarder.
We strongly recommend that you use the following UAPI function instead of this function:
-
Email::add_forwarder
— This function creates an email forwarder.
When you disable the Receive Mail role, the system disables this function.
Examples
WHM API (JSON)
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"
For more information, read our Calls from the WHM API documentation.
LiveAPI PHP Class
$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',
)
);
For more information, read our Guide to the LiveAPI System.
LiveAPI Perl Module
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',
}
);
For more information, read our Guide to the LiveAPI System.
cPanel Tag System (deprecated)
- cPanel tags are deprecated . We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI .
- cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
- For more information, read our Deprecated cPanel Tag Usage documentation.
Command Line
cpapi2 --user=username Email addforward domain=example.com email=forwardme%40example.com fwdopt=fwd fwdemail=fwdtome%40example.com
For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help
command.
Output (JSON)
{
"cpanelresult": {
"apiversion": 2,
"func": "addforward",
"data": [
{
"email": "forwardme@example.com",
"domain": "example.com",
"forward": "fwdtome@example.com"
}
],
"event": {
"result": 1
},
"module": "Email"
}
}
Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.
Parameters
Parameter | Type | Description | Possible values | Example |
---|---|---|---|---|
domain |
string | Required The domain. |
A valid domain on the account. |
example.com |
email |
string | Required The email address to forward. |
An email address on the account. |
forwardme@example.com |
fwdopt |
string | Required The method to use to handle the email address's mail. |
|
fwd |
fwdemail |
string | The email address to which the system forwards messages. Note:
|
A valid email address. |
fwdtome@example.com |
fwdsystem |
string | The system user to whom the system forwards messages. Note:
You must use this parameter if you used the |
An account on the system. For example, a reseller or cPanel account's name. | user |
failmsgs |
string | The failure message for the message's sender. Note: Use this parameter if you used the This parameter defaults to |
A valid string. | Nobody's home. |
pipefwd |
string | The application to which the system pipes messages. Note:You must use this parameter if you used the |
The location of a program or script, relative to the account's home directory. | mailscript.pl |
Returns
Return | Type | Description | Possible values | Example |
---|---|---|---|---|
domain |
string | The domain. |
A valid domain on the account. |
example.com |
email |
string | The email address. | An email address on the account. | forwardme@example.com |
forward |
string | The method that the system will use to handle the address's email. |
|
forwardtome@example.com |
reason |
string | A reason for failure. Note:This function only returns a |
A string that describes the error. |
This is an error message. |
result |
Boolean | Whether the function succeeded. |
|
1 |