Dart
Dart
Amazon SES v2: Verify a sending domain with Easy DKIM
See more Amazon SES Examples
Use a domain you control. Run once to create the regional identity, publish the returned CNAMEs with your DNS provider, then set checkExisting to true and run again to read the status. The target suffix comes from SES. If your DNS provider appends the domain automatically, enter just the relative record name.
CreateEmailIdentity · GetEmailIdentity · Easy DKIM records
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
final domainName = 'example.com';
final checkExisting = false;
// 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);
}
var responseText = '';
if (checkExisting) {
final path = CkStringBuilder();
path.append('/v2/email/identities/');
path.append(domainName);
responseText = rest.fullRequestNoBody('GET', path.getAsString());
} else {
final identity = CkJsonObject();
identity.updateString('EmailIdentity', domainName);
rest.addHeader('Content-Type', 'application/json');
responseText = rest.fullRequestString('POST', '/v2/email/identities', identity.emit());
}
if (!rest.lastMethodSuccess) {
print(rest.lastErrorText);
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;
}
print('DKIM status: ${response.stringOf('DkimAttributes.Status')}');
print('Verified for sending: ${response.boolOf('VerifiedForSendingStatus')}');
final count = response.sizeOfArray('DkimAttributes.Tokens');
if (count < 1) {
print('No Easy DKIM tokens were returned. Check this identity\'s DKIM configuration.');
return;
}
if (!response.hasMember('DkimAttributes.SigningHostedZone')) {
print('Find the CNAME targets for this identity in the SES console.');
return;
}
final zone = response.stringOf('DkimAttributes.SigningHostedZone');
var i = 0;
while (i < count) {
response.i = i;
final token = response.stringOf('DkimAttributes.Tokens[i]');
print('$token._domainkey.$domainName CNAME $token.$zone');
i++;
}
}