Zarządzanie ustawieniami urlopu
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
W Ustawieniach możesz skonfigurować zaplanowaną automatyczną odpowiedź na koncie.
Informacje o tym, jak pobrać lub zaktualizować ustawienia, znajdziesz w tym artykule.
Konfigurowanie odpowiedzi automatycznej
Automatyczna odpowiedź wymaga tematu i treści odpowiedzi w formacie HTML lub zwykłego tekstu. Można ją włączyć na czas nieokreślony lub na określony okres. Możesz też ograniczyć automatyczne odpowiedzi do znanych kontaktów lub członków domeny.
Przykład ustawienia automatycznej odpowiedzi na określony czas z ograniczeniem odpowiedzi do użytkowników w tej samej domenie:
Aby wyłączyć automatyczną odpowiedź, zaktualizuj zasób i ustaw wartość enableAutoReply
na false
. Jeśli skonfigurowano endTime
, odpowiedź automatyczna zostanie automatycznie wyłączona po upływie określonego czasu.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-29 UTC.
[null,null,["Ostatnia aktualizacja: 2025-08-29 UTC."],[],[],null,["# Managing Vacation Settings\n\nYou can use [Settings](/workspace/gmail/api/v1/reference/users/settings) to\nconfigure scheduled [auto-reply](https://support.google.com/mail/answer/25922) for an account.\n\nFor information on how to\n[get](/workspace/gmail/api/v1/reference/users/settings/getVacation) or\n[update](/workspace/gmail/api/v1/reference/users/settings/updateVacation),\nsee the [Settings reference](/workspace/gmail/api/v1/reference/users/settings).\n\nConfiguring auto-reply\n----------------------\n\nAuto-reply requires a response subject and body, either HTML or plain text. It\ncan be enabled indefinitely, or limited to a defined period of time. You can\nalso restrict auto-reply to known contacts or domain members.\n\nExample of setting an auto-reply for a fixed period of time, restricting replies\nto users in the same domain: \n\n### Java\n\ngmail/snippets/src/main/java/EnableAutoReply.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/gmail/snippets/src/main/java/EnableAutoReply.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.VacationSettings;\nimport com.google.auth.http.HttpCredentialsAdapter;\nimport com.google.auth.oauth2.GoogleCredentials;\nimport java.io.IOException;\nimport java.time.LocalDateTime;\nimport java.time.ZoneOffset;\nimport java.time.ZonedDateTime;\n\n/* Class to demonstrate the use of Gmail Enable Auto Reply API*/\npublic class EnableAutoReply {\n /**\n * Enables the auto reply\n *\n * @return the reply message and response metadata.\n * @throws IOException - if service account credentials file not found.\n */\n public static VacationSettings autoReply() 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_BASIC);\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 reply by restricting domain with start time and end time\n VacationSettings vacationSettings = new VacationSettings()\n .setEnableAutoReply(true)\n .setResponseBodyHtml(\n \"I am on vacation and will reply when I am back in the office. Thanks!\")\n .setRestrictToDomain(true)\n .setStartTime(LocalDateTime.now()\n .toEpochSecond(ZoneOffset.from(ZonedDateTime.now())) * 1000)\n .setEndTime(LocalDateTime.now().plusDays(7)\n .toEpochSecond(ZoneOffset.from(ZonedDateTime.now())) * 1000);\n\n VacationSettings response = service.users().settings()\n .updateVacation(\"me\", vacationSettings).execute();\n // Prints the auto-reply response body\n System.out.println(\"Enabled auto reply with message : \" + response.getResponseBodyHtml());\n return response;\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 auto reply: \" + e.getDetails());\n } else {\n throw e;\n }\n }\n return null;\n }\n}\n```\n\n### Python\n\ngmail/snippet/settings snippets/enable_auto_reply.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/gmail/snippet/settings snippets/enable_auto_reply.py) \n\n```python\nfrom datetime import datetime, timedelta\n\nimport google.auth\nfrom googleapiclient.discovery import build\nfrom googleapiclient.errors import HttpError\nfrom numpy import long\n\n\ndef enable_auto_reply():\n \"\"\"Enable auto reply.\n Returns:Draft object, including reply message and response 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 epoch = datetime.utcfromtimestamp(0)\n now = datetime.now()\n start_time = (now - epoch).total_seconds() * 1000\n end_time = (now + timedelta(days=7) - epoch).total_seconds() * 1000\n vacation_settings = {\n \"enableAutoReply\": True,\n \"responseBodyHtml\": (\n \"I am on vacation and will reply when I am \"\n \"back in the office. Thanks!\"\n ),\n \"restrictToDomain\": True,\n \"startTime\": long(start_time),\n \"endTime\": long(end_time),\n }\n\n # pylint: disable=E1101\n response = (\n service.users()\n .settings()\n .updateVacation(userId=\"me\", body=vacation_settings)\n .execute()\n )\n print(f\"Enabled AutoReply with message: {response.get('responseBodyHtml')}\")\n\n except HttpError as error:\n print(f\"An error occurred: {error}\")\n response = None\n\n return response\n\n\nif __name__ == \"__main__\":\n enable_auto_reply()\n```\n\nTo disable auto-reply, update the resource and set `enableAutoReply` to\n`false`. If an `endTime` is configured, auto-reply will automatically disable\nonce the specified time has passed."]]