Objective-C
Objective-C
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 Objective-C Downloads
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoAuthAws.h>
#import <CkoSocket.h>
#import <CkoRest.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = NO;
NSString *messageId = @"YOUR_SES_MESSAGE_ID";
CkoStringBuilder *path = [[CkoStringBuilder alloc] init];
[path Append: @"/v2/email/insights/"];
[path Append: messageId];
[path Append: @"/"];
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
NSString *region = @"us-west-2";
CkoStringBuilder *host = [[CkoStringBuilder alloc] init];
[host Append: @"email."];
[host Append: region];
[host Append: @".amazonaws.com"];
CkoAuthAws *signer = [[CkoAuthAws alloc] init];
// Supply the credentials from your application's credential provider.
signer.AccessKey = @"AWS_ACCESS_KEY_ID";
signer.SecretKey = @"AWS_SECRET_ACCESS_KEY";
signer.Region = region;
signer.ServiceName = @"ses";
CkoSocket *connection = [[CkoSocket alloc] init];
connection.RequireSslCertVerify = YES;
success = [connection Connect: [host GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 10000]];
if (success != YES) {
NSLog(@"%@",connection.LastErrorText);
return;
}
CkoRest *rest = [[CkoRest alloc] init];
success = [rest UseConnection: connection autoReconnect: NO];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
success = [rest SetAuthAws: signer];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
// For temporary AWS credentials, supply the session token from the same provider.
NSString *sessionToken = @"";
if (sessionToken != @"") {
[rest AddQueryParam: @"X-Amz-Security-Token" value: sessionToken];
}
NSString *responseText = [rest FullRequestNoBody: @"GET" uriPath: [path GetAsString]];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
if ([rest.ResponseStatusCode intValue] == 404) {
NSLog(@"%@",@"No insights found. Check the Region, message ID, and VDM coverage.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d%@%@",@"SES returned HTTP ",[rest.ResponseStatusCode intValue],@" ",responseText);
return;
}
CkoJsonObject *response = [[CkoJsonObject alloc] init];
success = [response Load: responseText];
if (success != YES) {
NSLog(@"%@",response.LastErrorText);
return;
}
int i = 0;
int recipients = [[response SizeOfArray: @"Insights"] intValue];
if (recipients < 1) {
NSLog(@"%@",@"No recipient history is available yet.");
}
while ((i < recipients)) {
response.I = [NSNumber numberWithInt: i];
NSLog(@"%@",[response StringOf: @"Insights[i].Destination"]);
int j = 0;
int count = [[response SizeOfArray: @"Insights[i].Events"] intValue];
while ((j < count)) {
response.J = [NSNumber numberWithInt: j];
NSLog(@"%@%@%@",[response StringOf: @"Insights[i].Events[j].Timestamp"],@" ",[response StringOf: @"Insights[i].Events[j].Type"]);
if ([response HasMember: @"Insights[i].Events[j].Details.Bounce.DiagnosticCode"] == YES) {
NSLog(@"%@",[response StringOf: @"Insights[i].Events[j].Details.Bounce.DiagnosticCode"]);
}
if ([response HasMember: @"Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"] == YES) {
NSLog(@"%@",[response StringOf: @"Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"]);
}
j = j + 1;
}
i = i + 1;
}