Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Assumes Chilkat is unlocked. See Global Unlock Sample.

  final messageId = 'YOUR_SES_MESSAGE_ID';
  final path = CkStringBuilder();
  path.append('/v2/email/insights/');
  path.append(messageId);
  path.append('/');
  // Use the same AWS Region for the identity, endpoint, and Signature Version 4.
  final region = 'us-west-2';
  final host = CkStringBuilder();
  host.append('email.');
  host.append(region);
  host.append('.amazonaws.com');

  final signer = CkAuthAws();
  // 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';

  final connection = CkSocket();
  connection.requireSslCertVerify = true;
  try {
    connection.connect(host.getAsString(), 443, true, 10000);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final rest = CkRest();
  try {
    rest.useConnection(connection, false);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    rest.setAuthAws(signer);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // For temporary AWS credentials, supply the session token from the same provider.
  final sessionToken = '';
  if (sessionToken != '') {
    rest.addQueryParam('X-Amz-Security-Token', sessionToken);
  }

  final String responseText;
  try {
    responseText = rest.fullRequestNoBody('GET', path.getAsString());
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  if (rest.responseStatusCode == 404) {
    print('No insights found. Check the Region, message ID, and VDM coverage.');
    return;
  }

  if (rest.responseStatusCode != 200) {
    print('SES returned HTTP ${rest.responseStatusCode} $responseText');
    return;
  }

  final response = CkJsonObject();
  try {
    response.load(responseText);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  var i = 0;
  final recipients = response.sizeOfArray('Insights');
  if (recipients < 1) {
    print('No recipient history is available yet.');
  }

  while (i < recipients) {
    response.i = i;
    print(response.stringOf('Insights[i].Destination'));
    var j = 0;
    final count = response.sizeOfArray('Insights[i].Events');
    while (j < count) {
      response.j = j;
      print('${response.stringOf('Insights[i].Events[j].Timestamp')} ${response.stringOf('Insights[i].Events[j].Type')}');
      if (response.hasMember('Insights[i].Events[j].Details.Bounce.DiagnosticCode')) {
        print(response.stringOf('Insights[i].Events[j].Details.Bounce.DiagnosticCode'));
      }

      if (response.hasMember('Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType')) {
        print(response.stringOf('Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType'));
      }

      j++;
    }

    i++;
  }
}