2
votes

I am new to GAS and Gmail API and trying to trigger emails from Google spreadsheet using Google Apps Script with Gmail API.

My question is that, is it possible to send emails after including the user's Gmail signature in the email?

So I want to know if I can access my signature from my Gmail Account and send the email along with it. Is it possible with Gmail API and apps script ?

Here is what I got so far.

https://developers.google.com/admin-sdk/email-settings/#manage_signature_settings - DEPRECATED so below link should work

https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs

From the above link I think I should use the sendAs resource. Not sure how I can trigger email.

I would really appreciate if someone can show me a test email using Google Apps Script and Gmail API which includes signature. The email can be with plain text.

Thanks again. I am really in need of this. Please help me.

1
What code are you using right now to trigger the email? In your sheet, you would use the GmailApp Class rather than MailApp. More here on using the Gmail API in Spreadsheets.Brian
Thanks for replying Brian. I normally use GmailApp or MailApp something like this.. MailApp.sendEmail(to, subject,'',{htmlBody: body, cc:''+cc , bcc: ''+bcc}); But with that can I include my Gmail signature also ? If that is possible then my problem is solved.Prahlad
Got it. So, no, you cannot access signatures from the standard GmailApp Class. You'll need to use the Advanced Google Services in the answer below.Brian

1 Answers

1
votes

From the docs it seems that it is indeed possible.

To UPDATE, you need to send a PUT request to this resource:

PUT https://www.googleapis.com/gmail/v1/users/userId/settings/sendAs/signature where userId is your user identification ID and signature is one of the settings from the list below

{
  "sendAsEmail": string,
  "displayName": string,
  "replyToAddress": string,
  "signature": string,
  "isPrimary": boolean,
  "isDefault": boolean,
  "treatAsAlias": boolean,
  "smtpMsa": {
    "host": string,
    "port": integer,
    "username": string,
    "password": string,
    "securityMode": string
  },
  "verificationStatus": string
}