การจัดการการส่งต่อ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คุณใช้การตั้งค่าเพื่อ
กำหนดค่าการส่งต่อสำหรับบัญชีได้ หากต้องการใช้เป็นอีเมลสำหรับการส่งต่อ
อีเมลต้องเป็นไปตามเกณฑ์ใดเกณฑ์หนึ่งต่อไปนี้
- อีเมลได้รับการยืนยันแล้ว ดูข้อมูลเพิ่มเติมได้ที่
สร้างและยืนยันที่อยู่อีเมลสำหรับการส่งต่อ
- อีเมลอยู่ในโดเมนเดียวกับผู้ส่ง
- อีเมลเป็นของโดเมนย่อยภายในโดเมนเดียวกันของผู้ส่ง
- อีเมลเป็นของชื่อแทนโดเมนที่กำหนดค่าเป็นส่วนหนึ่งของบัญชี 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."]]