Issue
So I am sending an email reply through SendGrid and I have a message object something like this:
message = {
"personalizations": context["personalizations"],
"from": {"email": context["sender_email"]},
"subject": context["subject"],
"content": [{"type": MimeType.html, "value": context["body"]}],
"reply_to": {"email": context["reply_to"]},
"headers": {"In-Reply-To": "<Prev-Message-ID>",
"References": "<Prev-Message-ID>",
}
}
sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))
sg.send(message)
Now when I go to the 'Show Original' in Gmail, the email does have References and In-Reply-To in headers. Something like this:
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=us-ascii
Date: Thu, 04 Aug 2022 05:47:05 +0000 (UTC)
From: test.Taylor-Hood_b56ef494-4d5e-4568-bcf5-
[email protected]
Mime-Version: 1.0
Message-ID: <3S2bF8n9Rj-0eNQWf172Gw@geopod-ismtpd-4-0>
Subject: Hakunamatata!!!
Reply-To:
[email protected]
In-Reply-To: <CABQc7oqgKENUUAz6Mg4kdS7ZS8Q3Wq95DPNo-O2-
[email protected]>
References: <CABQc7oqgKENUUAz6Mg4kdS7ZS8Q3Wq95DPNo-O2-
[email protected]>
However, the email I send is never appended as a reply and always makes a new thread. What am I doing wrong?? Is it about the subject of the email which I send in reply?? I have tried doing Re: The Subject, but it still doesn't work. I have to display the whole conversation as a thread having sub-threads in my product and I'm stuck.
Solution
To reply in a thread you need to include a few things.
Firstly, add the In-Reply-To
and References
headers to the email both with the ID of the email you are replying to.
That will cause the email to thread, but if you are looking to emulate email client behaviour, you will also need to send the previous email's content, normally after the new content in the email.
Answered By - philnash
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.