Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
messageId: PWideChar;
path: HCkStringBuilder;
region: PWideChar;
host: HCkStringBuilder;
signer: HCkAuthAws;
connection: HCkSocket;
rest: HCkRest;
sessionToken: PWideChar;
responseText: PWideChar;
response: HCkJsonObject;
i: Integer;
recipients: Integer;
j: Integer;
count: Integer;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success := False;
messageId := 'YOUR_SES_MESSAGE_ID';
path := CkStringBuilder_Create();
CkStringBuilder_Append(path,'/v2/email/insights/');
CkStringBuilder_Append(path,messageId);
CkStringBuilder_Append(path,'/');
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
region := 'us-west-2';
host := CkStringBuilder_Create();
CkStringBuilder_Append(host,'email.');
CkStringBuilder_Append(host,region);
CkStringBuilder_Append(host,'.amazonaws.com');
signer := CkAuthAws_Create();
// Supply the credentials from your application's credential provider.
CkAuthAws_putAccessKey(signer,'AWS_ACCESS_KEY_ID');
CkAuthAws_putSecretKey(signer,'AWS_SECRET_ACCESS_KEY');
CkAuthAws_putRegion(signer,region);
CkAuthAws_putServiceName(signer,'ses');
connection := CkSocket_Create();
CkSocket_putRequireSslCertVerify(connection,True);
success := CkSocket_Connect(connection,CkStringBuilder__getAsString(host),443,True,10000);
if (success <> True) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(connection));
Exit;
end;
rest := CkRest_Create();
success := CkRest_UseConnection(rest,connection,False);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
success := CkRest_SetAuthAws(rest,signer);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
// For temporary AWS credentials, supply the session token from the same provider.
sessionToken := '';
if (sessionToken <> '') then
begin
CkRest_AddQueryParam(rest,'X-Amz-Security-Token',sessionToken);
end;
responseText := CkRest__fullRequestNoBody(rest,'GET',CkStringBuilder__getAsString(path));
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
if (CkRest_getResponseStatusCode(rest) = 404) then
begin
Memo1.Lines.Add('No insights found. Check the Region, message ID, and VDM coverage.');
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('SES returned HTTP ' + IntToStr(CkRest_getResponseStatusCode(rest)) + ' ' + responseText);
Exit;
end;
response := CkJsonObject_Create();
success := CkJsonObject_Load(response,responseText);
if (success <> True) then
begin
Memo1.Lines.Add(CkJsonObject__lastErrorText(response));
Exit;
end;
i := 0;
recipients := CkJsonObject_SizeOfArray(response,'Insights');
if (recipients < 1) then
begin
Memo1.Lines.Add('No recipient history is available yet.');
end;
while (i < recipients) do
begin
CkJsonObject_putI(response,i);
Memo1.Lines.Add(CkJsonObject__stringOf(response,'Insights[i].Destination'));
j := 0;
count := CkJsonObject_SizeOfArray(response,'Insights[i].Events');
while (j < count) do
begin
CkJsonObject_putJ(response,j);
Memo1.Lines.Add(CkJsonObject__stringOf(response,'Insights[i].Events[j].Timestamp') + ' ' + CkJsonObject__stringOf(response,'Insights[i].Events[j].Type'));
if (CkJsonObject_HasMember(response,'Insights[i].Events[j].Details.Bounce.DiagnosticCode') = True) then
begin
Memo1.Lines.Add(CkJsonObject__stringOf(response,'Insights[i].Events[j].Details.Bounce.DiagnosticCode'));
end;
if (CkJsonObject_HasMember(response,'Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType') = True) then
begin
Memo1.Lines.Add(CkJsonObject__stringOf(response,'Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType'));
end;
j := j + 1;
end;
i := i + 1;
end;
CkStringBuilder_Dispose(path);
CkStringBuilder_Dispose(host);
CkAuthAws_Dispose(signer);
CkSocket_Dispose(connection);
CkRest_Dispose(rest);
CkJsonObject_Dispose(response);