You need to sign in to do that
Don't have an account?

Require Help with Single Email Messaging
The requirement is
- Send notification emails to a particular email address whenever there is an email activity in a case. The notification should contain the email body.
- The notification emails should contain the attachments that were part of the email that triggered the notification.
- The notification emails of case should form a conversation thread in gmail (the specified email address is gmail)
I am able to complete the first 2 requirements, but the 3rd one is causing troubles. It works partially though. With all that I have heard Gmail uses the Subject line to group emails into a conversation thread. I have a constant Subject but still the notification emails create new conversation threads for each new day.
Example
Day 1 – there are 8 email activities in the case 1 and there are 2 email activities in case 2. The apex code sends 8 notifications related to case 1 that form a conversation thread and 2 notifications for case 2 that form another conversation thread. (this is correct)
Day 2 – there are 3 email activities in case 1 and there are 4 email activities in case 2. The apex code sends 3 notifications related to case 1 but this forms a new conversation thread and is not part of the same conversation thread created on day 1.
How can I form a single thread for each case instead of single thread of each case on each day?
I tried using the setInReplyTo and setReferences but got errors and the notification was not sent. Will this help in the threading problem, what are the other options?
Thanks
KD
The In-Reply-To: email header should be a single Message-ID, per the RFC that defines Internet messaging.
Message-IDs are intended to be globally unique, and take the form:
<unique-local-message-identifier@fully.qualified.domain.name>
For example, here's the Message-ID header from a VF template message I got today:
Message-ID: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>
So a reply to that message would have the following header (in order to thread correctly):
In-Reply-To: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>
So, In order to set the "In-Reply-To:" header correctly, you would need to either generate and store the Message-ID of the first message in your intended thread, or at least capture the Message-ID that Salesforce generates. It doesn't look like the email methods allow for setting the Message-ID, or the fetching of the SF-generated Message-ID. Or, if the Case is generated from an email in the first place, you could parse that Message-ID out and use it in the In-Reply-To headers.
I suspect, but don't know for sure, that if you generated an In-Reply-To header with a correctly-formed Message-ID for all the messages on a Case, they would thread correctly in Gmail, even if no message with that Message-ID actually exists. I'm an email nerd, not an Apex coder, so I can't give you specific code, but if I were writing it as a regular Salesforce formula, it might be:
"<MyForceApp." & Case.ID & "@customdomain.my.salesforce.com>"
Or if I wanted a unique thread per day, I could do:
"<MyForceApp." & Case.ID & "." & TEXT(TODAY()) & "@customdomain.my.salesforce.com>"
Hope that helps!
All Answers
I don't have much experience with the email system but I do know that the inReplyTo can be important.
See this external blog post that seems to indicate that it's used in threading.
The In-Reply-To: email header should be a single Message-ID, per the RFC that defines Internet messaging.
Message-IDs are intended to be globally unique, and take the form:
<unique-local-message-identifier@fully.qualified.domain.name>
For example, here's the Message-ID header from a VF template message I got today:
Message-ID: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>
So a reply to that message would have the following header (in order to thread correctly):
In-Reply-To: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>
So, In order to set the "In-Reply-To:" header correctly, you would need to either generate and store the Message-ID of the first message in your intended thread, or at least capture the Message-ID that Salesforce generates. It doesn't look like the email methods allow for setting the Message-ID, or the fetching of the SF-generated Message-ID. Or, if the Case is generated from an email in the first place, you could parse that Message-ID out and use it in the In-Reply-To headers.
I suspect, but don't know for sure, that if you generated an In-Reply-To header with a correctly-formed Message-ID for all the messages on a Case, they would thread correctly in Gmail, even if no message with that Message-ID actually exists. I'm an email nerd, not an Apex coder, so I can't give you specific code, but if I were writing it as a regular Salesforce formula, it might be:
"<MyForceApp." & Case.ID & "@customdomain.my.salesforce.com>"
Or if I wanted a unique thread per day, I could do:
"<MyForceApp." & Case.ID & "." & TEXT(TODAY()) & "@customdomain.my.salesforce.com>"
Hope that helps!
Hi,
After much trial and error, I used the format provided by you on references instead of in-reply-to and it has worked for me. Thanks for your help.
KD
@KD123456, I have the exact same need, could you please elaborate on the solution that worked for you? What information did you add to the case notification emails, and how did you add it?
Thanks,
Jon
Thank You