Search code examples
apiemailgmailgmail-api

Gmail API: Include previous messages in the reply


I'm using Gmail API to send messages using endpoint as listed here https://developers.google.com/gmail/api/v1/reference/users/messages/send

Using the headers References and In-Reply-To threading works perfectly. However I'm unable to get the earlier messages quoted in the reply as would happen if the reply is composed in Gmail. Is there a way to do this or if there's a workaround?


Solution

  • If you go from Gmail UI to Show original you will see that the quotation of earlier messages is just part of the new message body:

    enter image description here

    It is not possible to quote the previous message automatically with the Gmail API, but you can do it yourself manually.

    enter image description here

    enter image description here

    For this you can retrieve the date from the headers and the message text the data of the previous message body, and then create manually a string that appends the data after >.

    Append then this manually created string to the end of your new message body.