Scenario: The requirement is to send mail through apex but the tricky part is to identify the old email email chain (that once started from Salesforce then received by the receiver then the receiver again replies) and send a mail on that chain.

  • For eg, with the help of Salesforce a receiver receives an email to respond with either yes or no, but somehow mistakenly the receiver replies with a wrong keyword.

  • Now, we need to fetch this mail chain and tell the user that please reply with a valid response by sending a mail.

Note : I was able to send mail but the mail is always getting sent as a fresh mail (not on the existing mail chain).

  • I guess using setReferences() method from Messaging.SingleEmailMessage Class we can do so but I'm unable to get what exact string should I pass into that method.

Hope I was able to make it clear!!

Any help would be much appreciated!!


1 Answer 1


This is from Googling only - no personal experience of this.

This Threading: Message-ID, References, In-Reply-To post says:

In practice, References has nothing other than the message identifiers, each preceded by exactly one space, all on one line:

 References: <[email protected]> <[email protected] <[email protected]>

This is the USENET References syntax. Writers should follow the same format.

Writers use References to indicate that a message has a parent. The last identifier in References identifies the parent. The first identifier in References identifies the first article in the same thread. There may be more identifiers in References, with grandparents preceding parents, etc. (The basic idea is that a writer should copy References from the parent and append the parent's Message-ID. However, if there are more than about ten identifiers listed, the writer should eliminate the second one.)

And you can get the Message-IDs in Apex via the InboundEmail.Header Class.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .