You can use Settings to configure scheduled auto-reply for an account.
For information on how to get or update, see the Settings reference.
Configuring auto-reply
Auto-reply requires a response subject and body, either HTML or plain text. It can be enabled indefinitely, or limited to a defined period of time. You can also restrict auto-reply to known contacts or domain members.
Example of setting an auto-reply for a fixed period of time, restricting replies to users in the same domain:
Java
VacationSettings vacationSettings = new VacationSettings()
.setEnableAutoReply(true)
.setResponseBodyHtml("I'm on vacation and will reply when I'm back in the office. Thanks!")
.setRestrictToDomain(true)
.setStartTime(LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) * 1000)
.setEndTime(LocalDateTime.now().plusDays(7).toEpochSecond(ZoneOffset.UTC) * 1000);
VacationSettings response = gmailService.users().settings().updateVacation("me", vacationSettings).execute();
Python
epoch = datetime.utcfromtimestamp(0)
now = datetime.now()
start_time = (now - epoch).total_seconds() * 1000
end_time = (now + timedelta(days=7) - epoch).total_seconds() * 1000
vacation_settings = {
'enableAutoReply': True,
'responseBodyHtml': "I'm on vacation and will reply when I'm "
"back in the office. Thanks!",
'restrictToDomain': True,
'startTime': long(start_time),
'endTime': long(end_time)
}
response = gmail_service.users().settings().\
updateVacation(userId='me', body=vacation_settings).execute()
To disable auto-reply, update the resource and set enableAutoReply
to
false
. If an endTime
is configured, auto-reply will automatically disable
once the specified time has passed.