So I am sending my email using sendgrid personalization 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"]}
}
sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))
sg.send(message)
Here context["personalization"] is an object as below:
{
"to": [{"email": applicant.email}],
"custom_args": {
"email_id": str(correspondance.id),
"env": settings.ENVIRONMENT
}
}
Sending and receiving the emails work fine. The problem is that I can't send an email as a reply to some email. Like a user sends me an email which I receive through sendgrid's inbound parse. Now I want to reply to the email I received.
A solution I found on the internet was that I have to add an 'in_reply_to' ID which I receive as Message_ID in inbound parse but that didn't work. I did 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"]},
"in_reply_to": message_id
}
sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))
sg.send(message)
Here the message_id is Message_ID I received in the inbound email's json.