1

I am sending an email (with custom arguments) to multiple recipients in To list and receiving one message id.

Now I am trying to use sendgrid email activity api to fetch email status by using the query by providing the custom argument.

In the response of this email activity, i am only receiving status of only one recipient but not getting other recipients status.

Is there anything that i am missing while sending the email or searching with email activity?

I have tried searching for the same email in sendgrid and i can see the status of individual recipients but unable to get the same information using email activity

vinay
  • 61
  • 7
  • 1
    You might consider setting up a webhook so that SendGrid will send you activity instead of you having to go look for it. You would definitely get events for each recipient. – Crowcoder Dec 01 '22 at 12:42
  • @Crowcoder yes, but we are having a job which runs every hour to fetch the status of the email based on the query. I don't need the status of all emails, but need only for specific custom arguments. – vinay Dec 01 '22 at 13:02
  • The API documentation shows one recipient address in the response schema, not an array of them so I assume that's why. In my experience SendGrid support is pretty good so you may want to ask them directly how you do it. – Crowcoder Dec 01 '22 at 13:17
  • @Crowcoder can you please share me the documentation link. I tried searching it but couldn't find one regarding this response – vinay Dec 01 '22 at 17:24
  • https://docs.sendgrid.com/api-reference/e-mail-activity/filter-messages-by-message-id – Crowcoder Dec 01 '22 at 17:44

1 Answers1

1

After doing some research and investigation, I could able to fix this.

I tried to search different mails by changing the query as part of the email activity api. I have found that it is returning multiple emails. So by this, i can see that there an array of mails returning from sendgrid response.

To drill down the issue, I have sent a single email to multiple recipients. In send grid activity, I have verified each recipient email to see if there is any difference which is causing my filter to not return the data.

I found that when a mail is sent to multiple recipients, the custom arguments were being added only to the first recipient of To email addresses, first recipient of CC etc.

Below is the code that I used to send the mail in C#.

    SendGridMessage msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, recipients, subject, plainText, htmlContent);
msg.AddCustomArgs(uniqueArgs);
SendGrid.Response response = await client.SendEmailAsync(msg);

It was never appending these custom arguments to rest of other recipients.

To fix this I have to use "AddGlobalCustomArgs" insteadof "AddCustomArgs" to add the arguments to the mail which is adding the arguments to all the recipient mails.

msg.AddGlobalCustomArgs(uniqueArgs);

After sending a mail using this, the custom arguments are getting added to all the recipients mails. Verified this for each recipient mail sent as part of Sendgrid activity.

Now, tried running the email api with the same query filter that i have, and now I am able retrieve all the emails that I have sent with custom arguments.

Hope this answer helps

vinay
  • 61
  • 7
  • This is great info! Thank you for sharing. So you are retrieving these email by querying by this custom argument? I would love to see the query code as well! – Swimburger Jan 18 '23 at 21:50
  • 1
    @Swimburger yes, am querying using the custom argument. You have to pass this as part of query in the URL of email activity. (unique_args['argument']="definition"). This is how you need to use. https://docs.sendgrid.com/for-developers/sending-email/getting-started-email-activity-api this is the URL for more info on the query to find the data from email activity api – vinay Feb 11 '23 at 18:10