अपने-आप जवाब देने की सुविधा के लिए, जवाब का विषय और मुख्य हिस्सा देना ज़रूरी है. यह एचटीएमएल या सामान्य टेक्स्ट में होना चाहिए. इसे हमेशा के लिए चालू किया जा सकता है या किसी तय समयसीमा के लिए चालू किया जा सकता है. आपके पास, अपने-आप जवाब देने की सुविधा को सिर्फ़ उन लोगों के लिए चालू करने का विकल्प भी होता है जिनके बारे में आपको पता है या जो डोमेन के सदस्य हैं.
किसी तय अवधि के लिए, अपने-आप जवाब देने की सुविधा सेट करने और जवाब देने की सुविधा को सिर्फ़ एक ही डोमेन के उपयोगकर्ताओं के लिए सीमित करने का उदाहरण:
importcom.google.api.client.googleapis.json.GoogleJsonError;importcom.google.api.client.googleapis.json.GoogleJsonResponseException;importcom.google.api.client.http.HttpRequestInitializer;importcom.google.api.client.http.javanet.NetHttpTransport;importcom.google.api.client.json.gson.GsonFactory;importcom.google.api.services.gmail.Gmail;importcom.google.api.services.gmail.GmailScopes;importcom.google.api.services.gmail.model.VacationSettings;importcom.google.auth.http.HttpCredentialsAdapter;importcom.google.auth.oauth2.GoogleCredentials;importjava.io.IOException;importjava.time.LocalDateTime;importjava.time.ZoneOffset;importjava.time.ZonedDateTime;/* Class to demonstrate the use of Gmail Enable Auto Reply API*/publicclassEnableAutoReply{/** * Enables the auto reply * * @return the reply message and response metadata. * @throws IOException - if service account credentials file not found. */publicstaticVacationSettingsautoReply()throwsIOException{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */GoogleCredentialscredentials=GoogleCredentials.getApplicationDefault().createScoped(GmailScopes.GMAIL_SETTINGS_BASIC);HttpRequestInitializerrequestInitializer=newHttpCredentialsAdapter(credentials);// Create the gmail API clientGmailservice=newGmail.Builder(newNetHttpTransport(),GsonFactory.getDefaultInstance(),requestInitializer).setApplicationName("Gmail samples").build();try{// Enable auto reply by restricting domain with start time and end timeVacationSettingsvacationSettings=newVacationSettings().setEnableAutoReply(true).setResponseBodyHtml("I am on vacation and will reply when I am back in the office. Thanks!").setRestrictToDomain(true).setStartTime(LocalDateTime.now().toEpochSecond(ZoneOffset.from(ZonedDateTime.now()))*1000).setEndTime(LocalDateTime.now().plusDays(7).toEpochSecond(ZoneOffset.from(ZonedDateTime.now()))*1000);VacationSettingsresponse=service.users().settings().updateVacation("me",vacationSettings).execute();// Prints the auto-reply response bodySystem.out.println("Enabled auto reply with message : "+response.getResponseBodyHtml());returnresponse;}catch(GoogleJsonResponseExceptione){// TODO(developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==403){System.err.println("Unable to enable auto reply: "+e.getDetails());}else{throwe;}}returnnull;}}
fromdatetimeimportdatetime,timedeltaimportgoogle.authfromgoogleapiclient.discoveryimportbuildfromgoogleapiclient.errorsimportHttpErrorfromnumpyimportlongdefenable_auto_reply():"""Enable auto reply. Returns:Draft object, including reply message and response meta data. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for the application. """creds,_=google.auth.default()try:# create gmail api clientservice=build("gmail","v1",credentials=creds)epoch=datetime.utcfromtimestamp(0)now=datetime.now()start_time=(now-epoch).total_seconds()*1000end_time=(now+timedelta(days=7)-epoch).total_seconds()*1000vacation_settings={"enableAutoReply":True,"responseBodyHtml":("I am on vacation and will reply when I am ""back in the office. Thanks!"),"restrictToDomain":True,"startTime":long(start_time),"endTime":long(end_time),}# pylint: disable=E1101response=(service.users().settings().updateVacation(userId="me",body=vacation_settings).execute())print(f"Enabled AutoReply with message: {response.get('responseBodyHtml')}")exceptHttpErroraserror:print(f"An error occurred: {error}")response=Nonereturnresponseif__name__=="__main__":enable_auto_reply()
अपने-आप जवाब देने की सुविधा बंद करने के लिए, संसाधन को अपडेट करें और enableAutoReply को false पर सेट करें. अगर endTime को कॉन्फ़िगर किया गया है, तो तय समय पूरा होने के बाद, अपने-आप जवाब देने की सुविधा अपने-आप बंद हो जाएगी.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-01 (UTC) को अपडेट किया गया."],[],[]]