By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have received a successful response of a email using gmail.users.messages.send() which is like
{ "id": "1231212312", "labelIds": ["UNREAD", "SENT", "INBOX"], "threadId": "23123123" }

I need to send an email again to the same email address but on the same thread not as a new email i.e using thread id to send email.

Need Help!

Hi, sorry for bothering but it happens to me...
I'm using the Python API but I can imagine that this affects to the API endpoint so it's language-agnostic and I don't know who I should contact.
Formerly, the e-mails with same subject were posted to the same thread but now they don't. I tried to add the thread_id as you can see in the output of my program but my gmail recipient doesn't get the e-mails threaded (though the sender does).

See below the output of my program (I removed part of the body['raw'] in case it included some private data I am not aware).
'Send e-mail with body: First message 2019-06-20 16:00:26.922694'
{'raw': 'Q29udGVudC1UeXBlOiB0ZXh0L...C5jb20K...uOTIyNjk0'}
'Got'
{u'id': u'16b753049239ba7c',
u'labelIds': [u'SENT'],
u'threadId': u'16b753049239ba7c'}
'============'
'Send e-mail with body: Second message 2019-06-20 16:00:26.922694'
{'raw': 'Q29udGVudC1UeXBlOiB0ZXh0...b...OjAwOjI2LjkyMjY5NA==', 'threadId': u' 16b753049239ba7c '}
'Got'
{u'id': u'16b75304c6165b0d',
u'labelIds': [u'SENT'],
u'threadId': u'16b753049239ba7c'}
'============'
'Send e-mail with body: Third message 2019-06-20 16:00:26.922694'
{'raw': 'Q29udGVudC1UeXBlOiB0ZXh0L...C5jb20KZn...TIyNjk0', 'threadId': u' 16b753049239ba7c '}
'Got'
{u'id': u'16b75304f40b1d95',
u'labelIds': [u'SENT'],
u'threadId': u'16b753049239ba7c'}
'============'

It looks that the threadId is ok and the sender have them in a thread, but as you can see in the screenshots I attached at the end of this message, the recipient doesn't have it.

I would need the GMail receivers to receive threaded messages as well.

Can you reopen this or tell me who may I contact?

I am aware that we are told that we need to use the "References" and "In-Reply-To" but I'm afraid the send endpoint doesn't give me that and in order to get the e-mail I sent I think I need further permissions (read e-mail?) I would prefer to avoid.

Screenshots:

Receiver doesn't get the e-mails threaded:

Sender get the e-mails threaded:

Hi @zorion ,

You just need to add thread id while creating the message.

def CreateMessage(sender, to, subject, message_text, threadId):  
    message = MIMEText(message_text)
    message['to'] = to
    message['from'] = sender
    message['subject'] = subject
    raw_message = base64.urlsafe_b64encode(message.as_string().encode("utf-8"))
    return { 'raw': raw_message.decode("utf-8"), 'threadId': threadId } 
          

Hi, thank for your comment, I already sent the threadId and I complained because it stopped working on June 2019. I am not sure if this is because we use G Suite or if it is working again without the References and In-Reply-To headers.
See https://developers.google.com/gmail/api/guides/sending#sending_messages

For your information:
We wanted to send a batch of e-mails during a batch process. On June 2019 just sending the threadId wasn't enough and we needed to send the References and In-Reply-To headers as well.
Our problem was that the first "send" didn't return the created message-id so we could not use it directly for the next messages.

We came up with a workaround. In order to group all the messages, besides the threadId (like you said) we made up a fake message-id and we add the headers with this fake message-id in all the messages we wanted grouped.
It still works today, so not bad at all.

Cheers!

Hi, thank for your comment, I already sent the threadId and I complained because it stopped working on June 2019. I am not sure if this is because we use G Suite or if it is working again without the References and In-Reply-To headers.
See https://developers.google.com/gmail/api/guides/sending#sending_messages

For your information:
We wanted to send a batch of e-mails during a batch process. On June 2019 just sending the threadId wasn't enough and we needed to send the References and In-Reply-To headers as well.
Our problem was that the first "send" didn't return the created message-id so we could not use it directly for the next messages.

We came up with a workaround. In order to group all the messages, besides the threadId (like you said) we made up a fake message-id and we add the headers with this fake message-id in all the messages we wanted grouped.
It still works today, so not bad at all.

Cheers!

Hello!
Can you please share the code for the same? I am working on the same problem, I need to reply to emails via the gmail API and all the replies should be in the same thread.