Managing Forwarding

You can use Settings to configure forwarding for an account. To be used as a forwarding email address, an address must fulfill one of the following criteria:

  • The email address has been verified. For further information, see Creating and verifying forwarding addresses
  • The email address belongs to the same domain as the sender.
  • The email address belongs to a subdomain within the same domain of the sender.
  • The email address belongs to a domain alias configured as part of the same Google Workspace account.

If the forwarding email address doesn't adhere to one of these rules, setting up forwarding using the API fails.

For information on how to create, list, get, or delete forwarding addresses, see the ForwardingAddresses reference.

For information on how to get or update forwarding settings, see the Settings reference

Creating and verifying forwarding addresses

You must create forwarding addresses prior to use. In some cases, users must also verify ownership of the address as well.

If Gmail requires user verification for a forwarding address, the address is returned with the status pending. A verification message is automatically sent to the target email address. The owner of the email address must complete the verification process before it can be used.

Forwarding addresses that do not require verification have a verification status of accepted.

Enabling auto-forwarding

Call the updateAutoForwarding method to enable auto-forwarding for an account. The call requires both a registered and verified forwarding address as well as an action to take on forwarded messages.

For example, to enable auto-forwarding and move forwarded messages to the trash:



/* Class to demonstrate the use of Gmail Enable Forwarding API */
public class EnableForwarding {
   * Enable the auto-forwarding for an account.
   * @param forwardingEmail - Email address of the recipient whose email will be forwarded.
   * @return forwarding id and metadata, {@code null} otherwise.
   * @throws IOException - if service account credentials file not found.
  public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);

    // Create the gmail API client
    Gmail service = new Gmail.Builder(new NetHttpTransport(),
        .setApplicationName("Gmail samples")

    try {
      // Enable auto-forwarding and move forwarded messages to the trash
      ForwardingAddress address = new ForwardingAddress()
      ForwardingAddress createAddressResult = service.users().settings().forwardingAddresses()
          .create("me", address).execute();
      if (createAddressResult.getVerificationStatus().equals("accepted")) {
        AutoForwarding autoForwarding = new AutoForwarding()
        autoForwarding =
            service.users().settings().updateAutoForwarding("me", autoForwarding).execute();
        return autoForwarding;
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 403) {
        System.err.println("Unable to enable forwarding: " + e.getDetails());
      } else {
        throw e;
    return null;


gmail/snippet/settings snippets/
from __future__ import print_function

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

def enable_forwarding():
    """Enable email forwarding.
    Returns:Draft object, including forwarding id and result meta data.

    Load pre-authorized user credentials from the environment.
    TODO(developer) - See
    for guides on implementing OAuth2 for the application.
    creds, _ = google.auth.default()

        # create gmail api client
        service = build('gmail', 'v1', credentials=creds)

        address = {'forwardingEmail': ''}

        # pylint: disable=E1101
        result = service.users().settings().forwardingAddresses(). \
            create(userId='me', body=address).execute()
        if result.get('verificationStatus') == 'accepted':
            body = {
                'emailAddress': result.get('forwardingEmail'),
                'enabled': True,
                'disposition': 'trash'
            # pylint: disable=E1101
            result = service.users().settings().updateAutoForwarding(
                userId='me', body=body).execute()
            print(F'Forwarding is enabled : {result}')

    except HttpError as error:
        print(F'An error occurred: {error}')
        result = None

    return result

if __name__ == '__main__':

To disable autoforwarding, call updateAutoForwarding and set the enabled property to false.

Forwarding specific messages

Auto-forwarding sends all received messages to the target account. To selectively forward messages, use filters to create rules that forward in response to message attributes or content.