@@ -0,0 +1,3400 @@
+// Copyright 2021 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0A%0A// %5BSTART gmail_enable_auto_reply%5D%0Aimport com.google.api.client.googleapis.json.GoogleJsonResponseException;%0Aimport com.google.api.client.http.HttpRequestInitializer;%0Aimport com.google.api.client.http.javanet.NetHttpTransport;%0Aimport com.google.api.client.json.gson.GsonFactory;%0Aimport com.google.api.services.gmail.Gmail;%0Aimport com.google.api.services.gmail.GmailScopes;%0Aimport com.google.api.services.gmail.model.VacationSettings;%0Aimport com.google.auth.http.HttpCredentialsAdapter;%0Aimport com.google.auth.oauth2.GoogleCredentials;%0Aimport java.io.IOException;%0Aimport java.time.LocalDateTime;%0Aimport java.time.ZoneOffset;%0Aimport java.time.ZonedDateTime;%0Aimport java.util.Collections;%0A%0A/* Class to demonstrate the use of Gmail Enable Auto Reply API*/%0Apublic class EnableAutoReply %7B%0A    /**%0A     * Enables the auto reply%0A     *%0A     * @throws IOException%0A     */%0A    public static void autoReply() throws IOException%7B%0A        // Load pre-authorized user credentials from the environment.%0A        // TODO(developer) - See https://developers.google.com/identity for%0A        // guides on implementing OAuth2 for your application.%0A        GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(GmailScopes.GMAIL_SETTINGS_BASIC));%0A        HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(%0A                credentials);%0A%0A        // Create the gmail API client%0A        Gmail service = new Gmail.Builder(new NetHttpTransport(),%0A                GsonFactory.getDefaultInstance(),%0A                requestInitializer)%0A                .setApplicationName(%22Gmail samples%22)%0A                .build();%0A%0A        try %7B%0A            // Enable auto reply by restricting domain with start time and end time%0A            VacationSettings vacationSettings = new VacationSettings()%0A                    .setEnableAutoReply(true)%0A                    .setResponseBodyHtml(%22I am on vacation and will reply when I am back in the office. Thanks!%22)%0A                    .setRestrictToDomain(true)%0A                    .setStartTime(LocalDateTime.now().toEpochSecond(ZoneOffset.from(ZonedDateTime.now())) * 1000)%0A                    .setEndTime(LocalDateTime.now().plusDays(7).toEpochSecond(ZoneOffset.from(ZonedDateTime.now())) * 1000);%0A%0A            VacationSettings response = service.users().settings().updateVacation(%22me%22, vacationSettings).execute();%0A            // Prints the auto-reply response body%0A            System.out.println(%22Enabled auto reply with message : %22+response.getResponseBodyHtml());%0A        %7D catch (GoogleJsonResponseException e) %7B%0A            // TODO(developer) - handle error appropriately%0A            System.err.println(%22Unable to enable auto reply: %22 + e.getDetails());%0A            throw e;%0A        %7D%0A    %7D%0A%7D%0A// %5BEND gmail_enable_auto_reply%5D

Enable Auto Reply gmail snippet (#162)