Search code examples
c#.nettwiliosendgridbulk-email

How to get the email activity status from send grid for a single email sent to multiple recipients


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


Solution

  • 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