مدیریت حمل و نقل
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
می توانید از تنظیمات برای پیکربندی بازارسال برای یک حساب استفاده کنید. برای استفاده به عنوان یک آدرس ایمیل حمل و نقل، یک آدرس باید یکی از معیارهای زیر را داشته باشد:
- آدرس ایمیل تایید شده است. برای اطلاعات بیشتر، به ایجاد و تأیید آدرس های بازارسال مراجعه کنید
- آدرس ایمیل متعلق به همان دامنه فرستنده است.
- آدرس ایمیل متعلق به یک زیر دامنه در همان دامنه فرستنده است.
- آدرس ایمیل متعلق به یک نام مستعار دامنه است که به عنوان بخشی از همان حساب Google Workspace پیکربندی شده است.
اگر آدرس ایمیل باز ارسال به یکی از این قوانین پایبند نباشد، راهاندازی بازارسال با استفاده از API انجام نمیشود.
برای اطلاعات در مورد نحوه ایجاد ، فهرست کردن ، دریافت یا حذف آدرسهای ارسال، به مرجع ForwardingAddresses مراجعه کنید.
برای اطلاعات در مورد نحوه دریافت یا بهروزرسانی تنظیمات ارسال، به مرجع تنظیمات مراجعه کنید
ایجاد و تأیید آدرس های ارسال
قبل از استفاده باید آدرس های فوروارد را ایجاد کنید . در برخی موارد، کاربران باید مالکیت آدرس را نیز تأیید کنند.
اگر Gmail به تأیید کاربر برای آدرس بازارسال نیاز داشته باشد، آدرس با وضعیت pending
بازگردانده میشود. یک پیام تأیید به طور خودکار به آدرس ایمیل مورد نظر ارسال می شود. مالک آدرس ایمیل باید مراحل تأیید را قبل از استفاده از آن تکمیل کند.
آدرسهای بازارسالی که نیازی به تأیید ندارند، وضعیت تأیید accepted
دارند.
فعال کردن بازارسال خودکار
برای فعال کردن بازارسال خودکار برای یک حساب، روش updateAutoForwarding را فراخوانی کنید. تماس نیاز به یک آدرس ارسال ثبت شده و تأیید شده و همچنین اقدامی برای انجام پیام های فوروارد شده دارد.
به عنوان مثال، برای فعال کردن بازارسال خودکار و انتقال پیام های ارسال شده به سطل زباله:
برای غیرفعال کردن ارسال خودکار، updateAutoForwarding را فراخوانی کنید و ویژگی enabled
روی false
قرار دهید.
ارسال پیام های خاص
ارسال خودکار تمام پیام های دریافتی را به حساب مورد نظر ارسال می کند. برای ارسال انتخابی پیامها، از فیلترها برای ایجاد قوانینی استفاده کنید که در پاسخ به ویژگیها یا محتوای پیام ارسال میشوند.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-30 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-30 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]