1

Has someone already use gmail API to create signature for a user with apps script ? I've seen this link : "https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs" But I don't know how to use it.

Thanks for your responses JPA

jp astier
  • 39
  • 1
  • 6
  • I added an answer as the question was pretty simple, but normally people would expect you to show any work you have tried and what errors you have received. – Spencer Easton Oct 21 '16 at 12:42

1 Answers1

3

This is possible using the Gmail advanced service: https://developers.google.com/apps-script/advanced/gmail

function setSignature() {
  var newSig = Gmail.newSendAs();
  newSig.signature = "MY NEW SIGNATURE!"
  Gmail.Users.Settings.SendAs.patch(newSig, "me", Session.getActiveUser().getEmail())
}
Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
  • Hi Spencer, thanks for your response. It works to change my signature, but not if I want to change the signature of another user. I'm logged in admin: to change the signature of the Admin -> ok to change the signature of another user, I get the error: Not Found (line 84, line "addAccountInformations") – jp astier Oct 21 '16 at 14:50
  • Gmail.Users.Settings.SendAs.patch(newSign,"toto@titi.com", "toto@titi.com"); I've got the error : Delegation denied for admin@titi.com (line 84, file "addAccountInformations") – jp astier Oct 21 '16 at 14:53
  • The Gmail API does not support domain delegation like the previous Email Settings API which is now depreciated. You will need to use a service account that has been given domain wide authorization. That means you will need to use the Gmail REST interface using UrlFetchApp service to make the calls instead of the Gmail service. This is because scripts can not run as a service account, only a user account. – Spencer Easton Oct 21 '16 at 15:36
  • Ok thanks Spencer I'll test your advice as soon as possible – jp astier Oct 21 '16 at 19:44
  • Hello Spencer All work fine now Thanks for your help – jp astier Oct 28 '16 at 06:23