休暇設定の管理
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
設定を使用して、アカウントのスケジュール設定された自動返信を構成できます。
取得または更新する方法については、設定項目の詳細をご覧ください。
自動返信の設定
自動返信には、HTML またはプレーン テキストのいずれかの形式で、返信の件名と本文が必要です。無期限で有効にすることも、定義された期間に限定することもできます。自動返信を既知の連絡先またはドメイン メンバーに制限することもできます。
一定期間の自動返信を設定し、返信を同じドメイン内のユーザーに制限する例:
自動返信を無効にするには、リソースを更新して enableAutoReply
を false
に設定します。endTime
が構成されている場合、指定した時間が経過すると自動返信は自動的に無効になります。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-29 UTC。
[null,null,["最終更新日 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."]]