3
votes

I am having trouble sending a reply to a previously sent message. In other words, I need to send an email (emailA), and then send another email in reply to emailA (emailB) regardless of whether the recipient responded to emailA.

I can create a draft, and send a draft using the API. After sending the draft, I get an ID, the output looks like this:

{u'labelIds': [u'SENT'], u'id': u'16303ecfd567afa3', u'threadId': u'16303ecad298cdd1'}

Then, I convert that 'id' into a Message-ID, using the following code:

mime_msg = GetMimeMessage(service, "[email protected]", message1['id'])

The output, given the above example, is:

<CACJxmNStP826HnWHKP_G=0ju7bGotmCPQ2C9RRWxPGMs9WMmew@mail.gmail.com>

Then, to send the next email (emailB), I add that Message-ID to the email's headers as follows:

  message = MIMEText(message_text)
  message['to'] = to
  message['from'] = sender
  message['subject'] = subject

  message['threadId'] = thread_id
  message["In-Reply-To"] = message_id
  message["References"] = message_id

I also ensure that the subject is identical.

Although the email appears as a reply in my gmail inbox, after sending to recipients outside of the gmail ("outside address" - Outlook/hotmail), the email does not appear as a reply.

Further, if I manually send an email and a reply to that email to the same outside address, the reply shows as expected (so this is not a problem with how the other domain's display).

Further, if I send the first email (emailA) via the API, and then create a reply draft, the draft appears as a reply in my gmail inbox, but when I manually send, the email still does not appear as a reply to the outside address.

1

1 Answers

0
votes

Sending messages

If you're trying to send a reply and want the email to thread, make sure that:

The Subject headers match The References and In-Reply-To headers follow the RFC 2822 standard.