転送の管理
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
設定を使用して、アカウントの転送を設定できます。転送用メールアドレスとして使用するには、次のいずれかの条件を満たしている必要があります。
- メールアドレスが確認されました。詳しくは、転送用アドレスの作成と確認をご覧ください。
- メールアドレスが送信者と同じドメインに属している。
- メールアドレスが、送信者と同じドメイン内のサブドメインに属している。
- メールアドレスは、同じ Google Workspace アカウントの一部として構成されたドメイン エイリアスに属しています。
転送用メールアドレスがこれらのルールのいずれかに準拠していない場合、API を使用した転送の設定は失敗します。
転送先アドレスの作成、一覧表示、取得、削除の方法については、ForwardingAddresses リファレンスをご覧ください。
転送設定を取得または更新する方法については、設定項目の詳細をご覧ください。
転送先アドレスの作成と確認
転送アドレスは、使用する前に作成する必要があります。場合によっては、ユーザーはアドレスの所有権も確認する必要があります。
Gmail で転送先アドレスのユーザー確認が必要な場合、アドレスはステータス pending
で返されます。確認メッセージが対象のメールアドレスに自動的に送信されます。メールアドレスを使用するには、その所有者が確認プロセスを完了する必要があります。
確認を必要としない転送先アドレスの確認ステータスは accepted
です。
自動転送を有効にする
updateAutoForwarding メソッドを呼び出して、アカウントの自動転送を有効にします。この呼び出しには、登録済みで確認済みの転送アドレスと、転送されたメッセージに対して行うアクションの両方が必要です。
たとえば、自動転送を有効にして、転送されたメールをゴミ箱に移動するには:
自動転送を無効にするには、updateAutoForwarding を呼び出し、enabled
プロパティを false
に設定します。
特定のメッセージを転送する
自動転送では、受信したすべてのメールが転送先のアカウントに送信されます。メールを選択的に転送するには、フィルタを使用して、メールの属性またはコンテンツに応じて転送するルールを作成します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-01 UTC。
[null,null,["最終更新日 2025-08-01 UTC。"],[],[],null,["# Managing Forwarding\n\nYou can use [Settings](/workspace/gmail/api/v1/reference/users/settings) to\nconfigure forwarding for an account. To be used as a forwarding email address,\nan address must fulfill one of the following criteria:\n\n- The email address has been verified. For further information, see [Creating and verifying forwarding addresses](#create)\n- The email address belongs to the same domain as the sender.\n- The email address belongs to a subdomain within the same domain of the sender.\n- The email address belongs to a domain alias configured as part of the same Google Workspace account.\n\nIf the forwarding email address doesn't adhere to one of these rules, setting up\nforwarding using the API fails.\n\nFor information on how to\n[create](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses/create),\n[list](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses/list),\n[get](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses/get),\nor [delete](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses/delete)\nforwarding addresses,\nsee the [ForwardingAddresses reference](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses).\n\nFor information on how to [get](/workspace/gmail/api/v1/reference/users/settings/getAutoForwarding) or\n[update](/workspace/gmail/api/v1/reference/users/settings/updateAutoForwarding) forwarding\nsettings, see the [Settings reference](/workspace/gmail/api/v1/reference/users/settings)\n\nCreating and verifying forwarding addresses\n-------------------------------------------\n\nYou must [create](/workspace/gmail/api/v1/reference/users/settings/forwardingAddresses/create)\nforwarding addresses prior to use. In some cases, users must also verify ownership of the\naddress as well.\n\nIf Gmail requires user verification for a forwarding address, the address is returned with the\nstatus `pending`. A verification message is automatically sent to the\ntarget email address. The owner of the email address must complete the verification\nprocess before it can be used.\n\nForwarding addresses that do not require verification have a verification status of `accepted`.\n\nEnabling auto-forwarding\n------------------------\n\nCall the [updateAutoForwarding](/workspace/gmail/api/v1/reference/users/settings/updateAutoForwarding)\nmethod to enable auto-forwarding for an account. The call requires both a registered\nand verified forwarding address as well as an action to take on forwarded messages.\n\nFor example, to enable auto-forwarding and move forwarded messages to the trash: \n\n### Java\n\ngmail/snippets/src/main/java/EnableForwarding.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/gmail/snippets/src/main/java/EnableForwarding.java) \n\n```java\nimport com.google.api.client.googleapis.json.GoogleJsonError;\nimport com.google.api.client.googleapis.json.GoogleJsonResponseException;\nimport com.google.api.client.http.HttpRequestInitializer;\nimport com.google.api.client.http.javanet.NetHttpTransport;\nimport com.google.api.client.json.gson.GsonFactory;\nimport com.google.api.services.gmail.Gmail;\nimport com.google.api.services.gmail.GmailScopes;\nimport com.google.api.services.gmail.model.AutoForwarding;\nimport com.google.api.services.gmail.model.ForwardingAddress;\nimport com.google.auth.http.HttpCredentialsAdapter;\nimport com.google.auth.oauth2.GoogleCredentials;\nimport java.io.IOException;\n\n/* Class to demonstrate the use of Gmail Enable Forwarding API */\npublic class EnableForwarding {\n /**\n * Enable the auto-forwarding for an account.\n *\n * @param forwardingEmail - Email address of the recipient whose email will be forwarded.\n * @return forwarding id and metadata, {@code null} otherwise.\n * @throws IOException - if service account credentials file not found.\n */\n public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws IOException {\n /* Load pre-authorized user credentials from the environment.\n TODO(developer) - See https://developers.google.com/identity for\n guides on implementing OAuth2 for your application. */\n GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()\n .createScoped(GmailScopes.GMAIL_SETTINGS_SHARING);\n HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);\n\n // Create the gmail API client\n Gmail service = new Gmail.Builder(new NetHttpTransport(),\n GsonFactory.getDefaultInstance(),\n requestInitializer)\n .setApplicationName(\"Gmail samples\")\n .build();\n\n try {\n // Enable auto-forwarding and move forwarded messages to the trash\n ForwardingAddress address = new ForwardingAddress()\n .setForwardingEmail(forwardingEmail);\n ForwardingAddress createAddressResult = service.users().settings().forwardingAddresses()\n .create(\"me\", address).execute();\n if (createAddressResult.getVerificationStatus().equals(\"accepted\")) {\n AutoForwarding autoForwarding = new AutoForwarding()\n .setEnabled(true)\n .setEmailAddress(address.getForwardingEmail())\n .setDisposition(\"trash\");\n autoForwarding =\n service.users().settings().updateAutoForwarding(\"me\", autoForwarding).execute();\n System.out.println(autoForwarding.toPrettyString());\n return autoForwarding;\n }\n } catch (GoogleJsonResponseException e) {\n // TODO(developer) - handle error appropriately\n GoogleJsonError error = e.getDetails();\n if (error.getCode() == 403) {\n System.err.println(\"Unable to enable forwarding: \" + e.getDetails());\n } else {\n throw e;\n }\n }\n return null;\n }\n}\n```\n\n### Python\n\ngmail/snippet/settings snippets/enable_forwarding.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/gmail/snippet/settings snippets/enable_forwarding.py) \n\n```python\nimport google.auth\nfrom googleapiclient.discovery import build\nfrom googleapiclient.errors import HttpError\n\n\ndef enable_forwarding():\n \"\"\"Enable email forwarding.\n Returns:Draft object, including forwarding id and result meta data.\n\n Load pre-authorized user credentials from the environment.\n TODO(developer) - See https://developers.google.com/identity\n for guides on implementing OAuth2 for the application.\n \"\"\"\n creds, _ = google.auth.default()\n\n try:\n # create gmail api client\n service = build(\"gmail\", \"v1\", credentials=creds)\n\n address = {\"forwardingEmail\": \"gduser1@workspacesamples.dev\"}\n\n # pylint: disable=E1101\n result = (\n service.users()\n .settings()\n .forwardingAddresses()\n .create(userId=\"me\", body=address)\n .execute()\n )\n if result.get(\"verificationStatus\") == \"accepted\":\n body = {\n \"emailAddress\": result.get(\"forwardingEmail\"),\n \"enabled\": True,\n \"disposition\": \"trash\",\n }\n # pylint: disable=E1101\n result = (\n service.users()\n .settings()\n .updateAutoForwarding(userId=\"me\", body=body)\n .execute()\n )\n print(f\"Forwarding is enabled : {result}\")\n\n except HttpError as error:\n print(f\"An error occurred: {error}\")\n result = None\n\n return result\n\n\nif __name__ == \"__main__\":\n enable_forwarding()\n```\n\nTo disable autoforwarding, call [updateAutoForwarding](/workspace/gmail/api/v1/reference/users/settings/updateAutoForwarding)\nand set the `enabled` property to `false`.\n\nForwarding specific messages\n----------------------------\n\nAuto-forwarding sends all received messages to the target account. To\nselectively forward messages, use [filters](/workspace/gmail/api/guides/filter_settings)\nto create rules that forward in response to message attributes or content."]]