sendgrid / sendgrid-java

The Official Twilio SendGrid Led, Community Driven Java API Library
https://sendgrid.com
MIT License
484 stars 408 forks source link

Email Activity API: How to retrieve contents of a specific email? #674

Closed icarrara closed 3 years ago

icarrara commented 3 years ago

I need to retrieve contents of a specific message, as for example sender email, target email, Subject, etc.

I used the below code:

SendGrid sg = new SendGrid("SG.xxxxxxxxxxxx");
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("messages");
request.addQueryParam("query", "msg_id="'O7MUu2GaQKODKy_Y2j0r4w.filterdrecv-p3las1-c477c4585-dg6pk-20-6032B583-20.0'");
request.addQueryParam("limit", "1");

sg.api(request);

I receive the below contents:

statusCode:200

body:{"messages":[]}

How I can retrieve original contents of the message as for example from email address, to email address, subject etc?

Thank you in advance for any help.

Ivano

icarrara commented 3 years ago

I just found that my API call is correct and in fact after almost a minute I'm able to retrieve the message I was looking for.

There are a few seconds between the new message sent and the availability of it in Email Activity. There is some chance to cut this intermediate time?

Thank you for any suggest.

Ivano

shwetha-manvinkurke commented 3 years ago

@icarrara It's not clear to me whether there is a delay in sending and receiving the email itself or just retrieving it using the email activity API. Either way, I would recommend you reach out to support for assistance as this doesn't look like a helper library issue.

icarrara commented 3 years ago

@shwetha-manvinkurke There are many minutes or hours after the message is delivered until you can get it from the Email Activity API. It is by design. So I'll close this issue. Thank you for your comment.