Java
Java
Amazon SES v2: Look up delivery history for a message ID
See more Amazon SES Examples
Enable Virtual Deliverability Manager for the sending account. Use the SES MessageId from a recent eligible send to a real test mailbox in the same Region. Mailbox simulator sends are excluded from VDM. Events are grouped by destination. Timestamps in the REST response are Unix epoch seconds.
GetMessageInsights · VDM dashboard
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.AuthAws;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.Socket;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
String messageId = "YOUR_SES_MESSAGE_ID";
StringBuilder path = new StringBuilder();
path.append("/v2/email/insights/");
path.append(messageId);
path.append("/");
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
String region = "us-west-2";
StringBuilder host = new StringBuilder();
host.append("email.");
host.append(region);
host.append(".amazonaws.com");
AuthAws signer = new AuthAws();
// Supply the credentials from your application's credential provider.
signer.setAccessKey("AWS_ACCESS_KEY_ID");
signer.setSecretKey("AWS_SECRET_ACCESS_KEY");
signer.setRegion(region);
signer.setServiceName("ses");
Socket connection = new Socket();
connection.setRequireSslCertVerify(true);
try {
connection.connect(host.getAsString(), 443, true, 10000);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Rest rest = new Rest();
try {
rest.useConnection(connection, false);
rest.setAuthAws(signer);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// For temporary AWS credentials, supply the session token from the same provider.
String sessionToken = "";
if (!"".equals(sessionToken)) {
rest.addQueryParam("X-Amz-Security-Token", sessionToken);
}
String responseText;
try {
responseText = rest.fullRequestNoBody("GET", path.getAsString());
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
if (rest.getResponseStatusCode() == 404) {
System.out.println("No insights found. Check the Region, message ID, and VDM coverage.");
return;
}
if (rest.getResponseStatusCode() != 200) {
System.out.println("SES returned HTTP " + rest.getResponseStatusCode() + " " + responseText);
return;
}
JsonObject response = new JsonObject();
try {
response.load(responseText);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
int i = 0;
int recipients = response.sizeOfArray("Insights");
if (recipients < 1) {
System.out.println("No recipient history is available yet.");
}
while (i < recipients) {
response.setI(i);
System.out.println(response.stringOf("Insights[i].Destination"));
int j = 0;
int count = response.sizeOfArray("Insights[i].Events");
while (j < count) {
response.setJ(j);
System.out.println(response.stringOf("Insights[i].Events[j].Timestamp") + " " + response.stringOf("Insights[i].Events[j].Type"));
if (response.hasMember("Insights[i].Events[j].Details.Bounce.DiagnosticCode")) {
System.out.println(response.stringOf("Insights[i].Events[j].Details.Bounce.DiagnosticCode"));
}
if (response.hasMember("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType")) {
System.out.println(response.stringOf("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"));
}
j = j + 1;
}
i = i + 1;
}
}
}