Creating threaded messages with Gmail API - gmail-api

I am using the Gmail "insert" API to create messages in Gmail. (I am not sending the message or replying to an existing message, these are just being created with labels and left there). I have a thread Id for my messages that I need to use to group them together in Gmail, but I can't seem to get it working - messages are shown in Gmail as separate, not in a thread. My first thought was to use the "threadId" property in the json of the insert, but this causes http error 404 ""Requested entity was not found."
In my RFC message headers, I am creating the relevant threading headers as follows:
Subject: Performance issue with libcurl 7.73
MIME-Version: 1.0
Message-ID: <17576c8ef0591c6e>
In-Reply-To: <17576c8ef0591c6e>
References: <17576c8ef0591c6e>
So I create 2 messages with the above headers, all values identical except that the 2nd subject begins with "Re:". Does not work to thread them together. Any ideas?

Related

GMAIL API returns different ThreadID than inboxSDK

Context: I am using the [PHP] Gmail API and InboxSDK.
When sending a message (with Gmail API), I output the message sent object (reference here).
It contains info about message ID and Thread ID.
What is happening?
Id and ThreadID is the same (ok: because it is the first message in the thread).
But if I check the received mail with InboxSDK, i see a different ThreadID than the one returned by GMAIL API.
Example of what is going on:
I send a Test email via API.
When checking the thread ID with InboxSDK though...
We can see both Thread Ids are different.
Maybe I am doing something wrong, can you please help me out with this?
Note: I tried this multiple times with multiple google accounts. The issue is constant.

Creating a message in an Inbox by Gmail thread via Gmai API

Steps to reproduce:
Send a message from Inbox
Create a 2nd message in that same thread using Gmail API's "insert" method
Delete the first message either from the API or from Gmail (but really delete it, not just put it into trash)
Result: the 2nd message seems to get somehow disconnected from the thread and Inbox acts weirdly on it (see video if curious -- the weird behaviour itself starts at 2:10).
Bug or feature?
How to avoid it?

Getting http 500 backend error when posting to Gmail API

I am using the Gmail API to put messages into a Google Apps email account. I use
the OAuth 2.0 authentication protocol with a service account. This is more or
less working fine. One of our customers has asked us to put messages
directly into a Google Vault. I don't see a Vault API, but I did find this
information related to the "insert" method (which is what we use to add
messages to a normal account):
parameter "deleted" (boolean): Mark the email as permanently deleted
(not TRASH) and only visible in Google Apps Vault to a Vault administrator.
Only used for Google Apps for Work accounts.
When I do this, some messages are accepted, but frequently I get http error
500 in response to the POST. The error text says "Backend Error". I thought
the pattern was that the first time the message was posted, it would work,
but the second time would generate the error. Therefore I was thinking it
was a duplicate check issue. However I now see some examples of messages
that fail immediately. The POST url looks like this:
https://www.googleapis.com/upload/gmail/v1/users/user#domain.com/messages?uploadType=multipart&internalDateSource=dateHeader&deleted=true&access_token=ABC...
As I mentioned, the same message to the same url (without deleted=true) will
always work. Any ideas what is causing the error?
Was just fighting this issue myself. Apparently the error has something to do if the message is compatible with the Google vault retention policies:
If I turn on a default policy of "Retain everything" then I've been able to get the messages to import correctly. HTH!
I'm using the import api method and the backendError seems to be related to filters/policies. For example we asked Google to reject messages with xls and macros and we get the error on mail with that kind of attachment

Sending threaded email from Google App Engine

I've got an app that's sending email from AppEngine, but each email looks like it's a unique message. Instead I want related emails to be threaded in my email client. Is there a specific header/format I need to use?
These emails are not necessarily in response to another email, so I don't have a Message-ID to plug into References. I've tried using a natural key in References and In-Reply-To to no avail.
I was able to thread a list of emails just by using the In-Reply-To header with your format <msg-identifier#host>.
Supposedly, msg-identifier is the identifier to the message you're replying to, but as you're not replying to any message but sending all of them out of thin air, creating a new ID and using it in all the emails you send will also do the trick.
I got this working by using both References and In-Reply-To with the format <identifier#systemname>. Maybe it'll work with less; I made several changes at once. If someone chimes in with that kind of detail I'll happily accept their answer instead of mine.

Google Channel API sends a message to all clients

I created a working Google Channel AP and now I would like to send a message to all clients.
I have two servlets. The first creates the channel and tells the clients the userid and token. The second one is called by an http post and should send the message.
To send a message to a client, I use:
channelService.sendMessage(new ChannelMessage(channelUserId, "This is a server message!"));
This sends the message just to one client. How could I send this to all?
Have I to store every Id which I use to create a channel and send the message for every id? How could I pass the Ids to the second servlet?
Using Channel API it is not possible to create one channel and then having many subscribers to it. The server creates a unique channel for individual JavaScript clients, so if you have the same Client ID the messages will be received only by one.
If you want to send the same message to multiple clients, in short, you will have to keep a track of active clients and send the same message to all of them.
If that approach sounds scary and messy, consider using PubNub for your push notification messages, where you can easily create one channel and have many subscribers. To make it run on Google App Engine is not that hard, since they support almost any platform or device.
I know this is an old question, but I just finished an open source project that uses the Channel API to implement a publish/subscribe model, i.e. you can have multiple users subscribe to a single topic, and then all those subscribers will be notified when anyone publishes a message to the topic. It also has some nice features like automatic message persistence if desired, and "return receipts", where a subscriber can be notified whenever OTHER subscribers receive that message. See https://github.com/adevine/gaewebpubsub#gae-web-pubsub. Licensed under Apache 2.0 license.

Resources