C#
C#
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 C# Downloads
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
string domainName = "example.com";
bool checkExisting = false;
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
string region = "us-west-2";
Chilkat.StringBuilder host = new Chilkat.StringBuilder();
host.Append("email.");
host.Append(region);
host.Append(".amazonaws.com");
Chilkat.AuthAws signer = new Chilkat.AuthAws();
// 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";
Chilkat.Socket connection = new Chilkat.Socket();
connection.RequireSslCertVerify = true;
success = connection.Connect(host.GetAsString(),443,true,10000);
if (success != true) {
Debug.WriteLine(connection.LastErrorText);
return;
}
Chilkat.Rest rest = new Chilkat.Rest();
success = rest.UseConnection(connection,false);
if (success != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
success = rest.SetAuthAws(signer);
if (success != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
// For temporary AWS credentials, supply the session token from the same provider.
string sessionToken = "";
if (sessionToken != "") {
rest.AddQueryParam("X-Amz-Security-Token",sessionToken);
}
string responseText = "";
if (checkExisting == true) {
Chilkat.StringBuilder path = new Chilkat.StringBuilder();
path.Append("/v2/email/identities/");
path.Append(domainName);
responseText = rest.FullRequestNoBody("GET",path.GetAsString());
}
else {
Chilkat.JsonObject identity = new Chilkat.JsonObject();
identity.UpdateString("EmailIdentity",domainName);
rest.AddHeader("Content-Type","application/json");
responseText = rest.FullRequestString("POST","/v2/email/identities",identity.Emit());
}
if (rest.LastMethodSuccess != true) {
Debug.WriteLine(rest.LastErrorText);
return;
}
if (rest.ResponseStatusCode != 200) {
Debug.WriteLine("SES returned HTTP " + Convert.ToString(rest.ResponseStatusCode) + " " + responseText);
return;
}
Chilkat.JsonObject response = new Chilkat.JsonObject();
success = response.Load(responseText);
if (success != true) {
Debug.WriteLine(response.LastErrorText);
return;
}
Debug.WriteLine("DKIM status: " + response.StringOf("DkimAttributes.Status"));
Debug.WriteLine("Verified for sending: " + Convert.ToString(response.BoolOf("VerifiedForSendingStatus")));
int count = response.SizeOfArray("DkimAttributes.Tokens");
if (count < 1) {
Debug.WriteLine("No Easy DKIM tokens were returned. Check this identity's DKIM configuration.");
return;
}
if (response.HasMember("DkimAttributes.SigningHostedZone") != true) {
Debug.WriteLine("Find the CNAME targets for this identity in the SES console.");
return;
}
string zone = response.StringOf("DkimAttributes.SigningHostedZone");
int i = 0;
while ((i < count)) {
response.I = i;
string token = response.StringOf("DkimAttributes.Tokens[i]");
Debug.WriteLine(token + "._domainkey." + domainName + " CNAME " + token + "." + zone);
i = i + 1;
}