Reputation: 2920
I have used sendgrid v3 api for sending emails. As mentioned in documentation of V3 API I use custom_args to get my params in event callback but it shows 400 bad request, while I use unique_args, the email was sent but the event callback does not send my unique_args params.
data = {"content": [{"value": "dfafds", "type": "text/plain"}], "attachments": [{"content": "UEsDBB......QACAgIAAA=", "type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "content_id": "BqzZqz7LaqO9", "filename": "Contactmanager-company.xlsx", "disposition": "attachment"}], "from": {"email": "[email protected]"}, "personalizations": [{"to": [{"email": "[email protected]"}], "custom_args": {"email_msg_id": 106}, "subject": "daff"}]}
Event callback response from send grid is
[{"sg_event_id": "aoDNXRAeRuaCAVRiutD-fg",
"sg_message_id": "epJqlw1JThGw--dDTC1oCQ.filter0099p3las1-8681-5B853F95-29.0",
"smtp-id": "[email protected]",
"timestamp": 1535459222,
"email": "[email protected]",
"event": "processed"}]
I need may custom_args in event callback reponse, In this response I need email_msg_id
What is missing here ?
Upvotes: 2
Views: 7187
Reputation: 29
from sendgrid.helpers.mail import Mail, CustomArg, Category
...
message = Mail(
from_email=email_config["from_email"],
to_emails=email_config["to_email"],
subject=email_config["subject"]
)
message.custom_arg = CustomArg(key="customer_name", value="ngoc lam")
message.category = Category(email_config["category"])
This code worked for me in python 3.13
Upvotes: 0
Reputation: 1
While sending mail through java we need to send a unique id from my side so that when webhook sends me the response I need to check the status of that mail by its unique id. here is my code in java...
MimeMessage message = (MimeMessage) getNewMessageInstance(); message.addHeader("unique_args", jsonRandomEmailStatisticsId);
And value of jsonRandomEmailStatisticsId is like {"unique_args":{"randomMessageId":"randomMessageId-308099455"}}
here I got a webhook response from SendGrid
[{ "category": [], "email": "[email protected]", "event": "processed", "marketing_campaign_id": 12345, "marketing_campaign_name": "campaign name", "post_type": "event", "sg_event_id": "sendgrid_internal_event_id", "sg_message_id": "sendgrid_internal_message_id", "sg_user_id": 12345, "smtp-id": "", "timestamp": 1442349428 }]
But SendGrid does not return random message id values in return of object response
Upvotes: 0
Reputation: 2920
In custom_args, data_type must be string. I fixed it using string data as "custom_args": {'email_msg_id': '106'}.
Upvotes: 6