# cPanel API 2 Functions - Email::addforward Warning: The cPanel API 2 system is deprecated. We **strongly** recommend that you use [UAPI](/cpanel/introduction) instead of cPanel API 2. ## Description This function creates an email forwarder. div Warning: br We **strongly** recommend that you use the following [UAPI](/cpanel/introduction/) function instead of this function: - `Email::add_forwarder` — This function creates an email forwarder. br div Important: br When you disable the [*Receive Mail* role](https://docs.cpanel.net/knowledge-base/general-systems-administration/how-to-use-server-profiles/#roles), the system **disables** this function. br ## Examples WHM API (JSON) ```undefined syntaxhighlighter-pre 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" ``` div Note: br For more information, read our [Calls from the WHM API](/whm/use-whm-api-to-call-cpanel-api-and-uapi) documentation. br LiveAPI PHP Class ```undefined syntaxhighlighter-pre $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', ) ); ``` div Note: br For more information, read our [Guide to the LiveAPI System](/guides/guide-to-the-liveapi-system/#guide-to-the-liveapi-system). br LiveAPI Perl Module ```undefined syntaxhighlighter-pre 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', } ); ``` div Note: br For more information, read our [Guide to the LiveAPI System](/guides/guide-to-the-liveapi-system). br cPanel Tag System (deprecated) Warnings: - cPanel tags are **deprecated**. We **strongly** recommend that you **only** use the [LiveAPI](/guides/guide-to-the-liveapi-system) 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](/guides/guide-to-the-liveapi-system). - 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](/cpanel-api-2/cpanel-api-2-deprecate-cpanel-tag-usage/) documentation. Command Line ```undefined syntaxhighlighter-pre cpapi2 --user=username Email addforward domain=example.com email=forwardme%40example.com fwdopt=fwd fwdemail=fwdtome%40example.com ``` div Note: br For more information and additional output options, read our [Guide to cPanel API 2](/cpanel-api-2/) documentation or run the `cpapi2 --help` command. br Output (JSON) ```undefined syntaxhighlighter-pre { "cpanelresult": { "apiversion": 2, "func": "addforward", "data": [ { "email": "forwardme@example.com", "domain": "example.com", "forward": "fwdtome@example.com" } ], "event": { "result": 1 }, "module": "Email" } } ``` div Note: br Use cPanel's *[API Shell](https://docs.cpanel.net/cpanel/advanced/api-shell-for-cpanel)* interface (*cPanel >> Home >> Advanced >> API Shell*) to directly test cPanel API calls. br ## Parameters table thead tr th strong Parameter th strong Type th strong Description th strong Possible values th strong Example tbody tr td code domain td em string td p strong Required p The domain. td p A valid domain on the account. td code example.com tr td code email td em string td p strong Required p The email address to forward. td div p An email address on the account. td code forwardme@example.com tr td code fwdopt td em string td p strong Required p The method to use to handle the email address's mail. td ul li code fwd — Forward messages to the addressed in the code fwdemail parameter. li code fail — Bounce messages back to the sender. This parameter also uses the failure message defined in the code failmsgs parameter. li code blackhole — Send messages to the code /dev/null/ directory. This method does strong not generate a failure notice. li code pipe — Pipe mail to the application defined by the code pipefwd parameter. li code system — Forward messages to the code fwdsystem system account. td code fwd tr td code fwdemail td em string td div p The email address to which the system forwards messages. Note: br ul li You strong must use this parameter if you used the code fwd method for the code fwdopt parameter. li You can pass multiple addresses to this parameter as a comma-separated list. td div p A valid email address. td code fwdtome@example.com tr td code fwdsystem td em string td div p The system user to whom the system forwards messages. p {% admonition type="info" name="Note:" %} {% /admonition %} p You strong must use this parameter if you used the code system method for the code fwdopt parameter. td An account on the system. For example, a reseller or cPanel account's name. td code user tr td code failmsgs td em string td div p The failure message for the message's sender. p Note: p Use this parameter if you used the code fail method for the code fwdopt parameter. p This parameter defaults to code No such person at this address. td A valid string. td code Nobody's home. tr td code pipefwd td em string td div p The application to which the system pipes messages. Note: p You strong must use this parameter if you used the code pipe method for the code fwdopt parameter. td The location of a program or script, relative to the account's home directory. td code mailscript.pl ## Returns table thead tr th strong Return th strong Type th strong Description th strong Possible values th strong Example tbody tr td code domain td em string td p The domain. td p A valid domain on the account. td code example.com tr td code email td em string td The email address. td An email address on the account. td code forwardme@example.com tr td code forward td em string td The method that the system will use to handle the address's email. td ul li An email address — The system forwards mail to this address. li code :fail: — The system bounces mail back to the sender and sends a failure message. li code :blackhole: — The system deletes mail strong without a failure message. li The path to an application — The system pipes mail to this application. li A username — The system forwards mail to this system account. td code forwardtome@example.com tr td code reason td em string td div p A reason for failure. Note: p This function only returns a code reason value if it failed. td p A string that describes the error. td code This is an error message. tr td code result td em Boolean td p Whether the function succeeded. td ul li code 1 — The function succeeded. li code 0 — The function failed. td code 1