Search code examples
google-apigmailgoogle-calendar-apigmail-apigoogle-workspace

Is there a possibility to update the out-of-office message in gmail and out-of-office state in calendar for employees?


We are using the google workspace solution and we would like to create a universal way for our employees to manage holidays, and vacations.

This basically means that we would give them a webpage where they can select when they would like to take a leave and then the software via the calendar api create an event in our "holiday calendar".

Also we would need it so it automatically sets their out of office message in GMAIL (because they usually forget this part).

Does anyone know whether this is possible? Because I could not find it in the documentation.


Solution

  • Yes its posible you should checkout updateVacation

    The documentation even shows some examples

    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();
    

    I recommend that you look into use a service account, if you set up domaind wide dedication to the user the service account will be able to set it on the users account. This will only work with workspace domain emails