Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
domainName: PWideChar;
checkExisting: Boolean;
region: PWideChar;
host: HCkStringBuilder;
signer: HCkAuthAws;
connection: HCkSocket;
rest: HCkRest;
sessionToken: PWideChar;
responseText: PWideChar;
path: HCkStringBuilder;
identity: HCkJsonObject;
response: HCkJsonObject;
count: Integer;
zone: PWideChar;
i: Integer;
token: PWideChar;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success := False;
domainName := 'example.com';
checkExisting := False;
// 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 := '';
if (checkExisting = True) then
begin
path := CkStringBuilder_Create();
CkStringBuilder_Append(path,'/v2/email/identities/');
CkStringBuilder_Append(path,domainName);
responseText := CkRest__fullRequestNoBody(rest,'GET',CkStringBuilder__getAsString(path));
end
else
begin
identity := CkJsonObject_Create();
CkJsonObject_UpdateString(identity,'EmailIdentity',domainName);
CkRest_AddHeader(rest,'Content-Type','application/json');
responseText := CkRest__fullRequestString(rest,'POST','/v2/email/identities',CkJsonObject__emit(identity));
end;
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
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;
Memo1.Lines.Add('DKIM status: ' + CkJsonObject__stringOf(response,'DkimAttributes.Status'));
Memo1.Lines.Add('Verified for sending: ' + IntToStr(Ord(CkJsonObject_BoolOf(response,'VerifiedForSendingStatus'))));
count := CkJsonObject_SizeOfArray(response,'DkimAttributes.Tokens');
if (count < 1) then
begin
Memo1.Lines.Add('No Easy DKIM tokens were returned. Check this identity''s DKIM configuration.');
Exit;
end;
if (CkJsonObject_HasMember(response,'DkimAttributes.SigningHostedZone') <> True) then
begin
Memo1.Lines.Add('Find the CNAME targets for this identity in the SES console.');
Exit;
end;
zone := CkJsonObject__stringOf(response,'DkimAttributes.SigningHostedZone');
i := 0;
while (i < count) do
begin
CkJsonObject_putI(response,i);
token := CkJsonObject__stringOf(response,'DkimAttributes.Tokens[i]');
Memo1.Lines.Add(token + '._domainkey.' + domainName + ' CNAME ' + token + '.' + zone);
i := i + 1;
end;
CkStringBuilder_Dispose(host);
CkAuthAws_Dispose(signer);
CkSocket_Dispose(connection);
CkRest_Dispose(rest);
CkStringBuilder_Dispose(path);
CkJsonObject_Dispose(identity);
CkJsonObject_Dispose(response);