1
votes

Is there a way to retrieve the signature of my Gmail account using Google Apps script?

I'm currently using Google Apps Script to send out emails and it would be nice to be able to append my email signature to the end of the email body because Google Apps Script doesn't automatically do so.

2

2 Answers

3
votes

While the Gmail API doesn't expose the signature, you can use a workaroud to grab the signature from Gmail.

  1. Create a new Gmail draft, put the word "signature" in the subject and save the draft.
  2. The body will include the signature by default. Do not modify the body.
  3. Save and Close the draft.

Go to Google Script editor and use this script to grab the signature.

function getGmailSignature() {
  var draft = GmailApp.search("subject:signature label:draft", 0, 1);
  return draft[0].getMessages()[0].getBody();
}
2
votes

Unfortunately, We don't have any user level access to retrieve our signature but, We have workaround, you can append signature simply copy your signature as a HTML [ Browser inspect mode] code from Gmail UI add to script variable, You can append this HTML string at the end of every email. You can make it dynamic like name and Email ID

Sample code

function myFunction() {
  var signHTML =
     '<br><br><br><br><table style="border-bottom:1px solid"><tbody><tr><td><table><tbody><tr><td><table style="padding-right:20px">'+
     '<tbody><tr><td></td></tr></tbody></table></td><td><table><tbody><tr><td><font face="open sans, sans-serif">'+
     '<span style="font-size: 12px;"><b>YOUR NAME</b></span></font></td></tr><tr><td><font face="open sans, sans-serif">'+
     '<span style="font-size: 12px;"><b>DESIGNATION&nbsp;</b></span></font>'+
     '</td></tr><tr><td><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-711-XXXX</span>'+
     '</div><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-8XXX09-XXXX</span></div>'+
     '<div><a href="https://www.searce.com" style="text-decoration:blink;vertical-align:top" target="_blank">'+
     '<span style="color:#000000;font-family:open sans,sans-serif;font-size:12px">www.yourComany.com</span></a>'+
     '</div></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td></td></tr></tbody></table>';
  MailApp.sendEmail({
    to: Session.getActiveUser().getEmail(),
    subject: "Upend signature at the end of mail",
    htmlBody: "Dear User</b>Signature testing" +
      signHTML,
  });
}

It works we are using this. Hope it helps you. :)