Using Gmail Java API to change the default signature in Gmail

Viewed 67

in the meantime Gmail supports multiple signatures for one mailadress. I am using the Gmail Java API to set a signature. Using the function setSignature("Text") it is possible to set a signature. Documentation see here: https://developers.google.com/resources/api-libraries/documentation/gmail/v1/java/latest/ Now, since I can set several signatures, it would be great to set a specific signature as default. Same as you can do in the gmail user interface. In the documentation I cannot find anything how to set a signature as default.

Maybe someone here has an idea how this could work or if there is any function implemented which is not added to the documentation.

I appreciate any help.

BR

2 Answers

I am interested in this can you send the code for this to me on github my name is List https://github.com/Wrightgo I am not very good at java I just like it but to my untrand eye I would do the following:

SendAs primaryAlias = null;
SendAsResponse aliases = gmailService.users().settings().sendAs().list("me").execute();
for (SendAs alias: aliases.getSendAs()) {
    if (alias.getIsPrimary()) {
        primaryAlias = alias;
        break;
    }
}
SendAs aliasSettings = new SendAs().setSignature("I heart cats.");
SendAs result = gmailService.users().settings().sendAs().patch(
        "me",
        primaryAlias.getSendAsEmail(),
        aliasSettings)
        .execute();
System.out.println("Updated signature for " + result.getDisplayName());

Yea thats the code from the documentation. This is to set a signature and it is working. But in the meantime google allows to set more signatures and to choose which signature is the default one (see attachment). enter image description here

Related