Reply to previously sent email

Hi,

I’m trying to send and email, and later send a reply to that same email.

import { Email } from 'meteor/email';

const messageId = 'some-random-string';
Emails.send({
  subject: 'Test',
  from: '<from-email>',
  to: '<to-email>',
  text: 'some text',
  messageId: messageId,

// later in time
Emails.send({
  subject: 'Text',
  from: '<from-email>',
  to: '<to-email>',
  text: 'more text',
  inReplyTo: messageId,
})

It’s not working because the message id I’m using is sent as “X-Google-Original-Message-ID”. Is it possible to get the message id of an email after sending it? Or alternatively generate a valid message id so that gmail won’t replace it with its own id?

From Wikipedia:

Message-IDs are required to have a specific format which is a subset of an email address [2] and to be globally unique. That is, no two different messages must ever have the same Message-ID. A common technique used by many message systems is to use a time and date stamp along with the local host’s domain name, e.g., 950124.162336@example.com [3]

It sounds like your Message-ID needs to have an @domain block added to be correct

Which seems to be confirmed by this question on SO:

(incidentally, including the @server.com portion of a message ID appears to be vital. Without that, using e.g. foobar-123-0 , our SMTP server simply ignored it and used it own autogenerated message ID)

Although the accepted answer says that gmail doesn’t care anyway:

The answer to why they are not threaded in Gmail is because Gmail’s threading is done according to the subject of the messages (it is not based on the “in-reply-to” or “references” field in the header).

So maybe you just have to try subject: `RE: ${subjectLine}` as well?

3 Likes

Adding the domain and using the same subject works:

let messageId = `${new Date().getTime()}-${projectId}@mydomain`;

Thanks!

1 Like