Reputation: 169
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.
Upvotes: 1
Views: 3266
Reputation: 11268
While the Gmail API doesn't expose the signature, you can use a workaroud to grab the signature from Gmail.
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();
}
Upvotes: 4
Reputation: 357
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 </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. :)
Upvotes: 2