Xbase++
Xbase++
Amazon SES v2: Request verification of a sender email address
See more Amazon SES Examples
Create an email identity in the AWS Region where the application sends mail. Use a mailbox you control and credentials with ses:CreateEmailIdentity. SES emails a verification link that expires after 24 hours. After following it, run Check sender verification status in the same Region.
CreateEmailIdentity · Verify an email identity
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRequest
LOCAL cRegion
LOCAL oHost
LOCAL oSigner
LOCAL oConnection
LOCAL oRest
LOCAL cSessionToken
LOCAL cResponseText
LOCAL oResult
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
nSuccess := 0
// Use an address whose inbox you can open. SES sends the verification link there.
oRequest := CreateObject("Chilkat.JsonObject")
oRequest:UpdateString("EmailIdentity", "sender+reports@example.com")
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
cRegion := "us-west-2"
oHost := CreateObject("Chilkat.StringBuilder")
oHost:Append("email.")
oHost:Append(cRegion)
oHost:Append(".amazonaws.com")
oSigner := CreateObject("Chilkat.AuthAws")
// Supply the credentials from your application's credential provider.
oSigner:AccessKey := "AWS_ACCESS_KEY_ID"
oSigner:SecretKey := "AWS_SECRET_ACCESS_KEY"
oSigner:Region := cRegion
oSigner:ServiceName := "ses"
oConnection := CreateObject("Chilkat.Socket")
oConnection:RequireSslCertVerify := 1
nSuccess := oConnection:Connect(oHost:GetAsString(), 443, 1, 10000)
IF (nSuccess != 1)
? oConnection:LastErrorText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
RETURN
ENDIF
oRest := CreateObject("Chilkat.Rest")
nSuccess := oRest:UseConnection(oConnection, 0)
IF (nSuccess != 1)
? oRest:LastErrorText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
RETURN
ENDIF
nSuccess := oRest:SetAuthAws(oSigner)
IF (nSuccess != 1)
? oRest:LastErrorText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
RETURN
ENDIF
// For temporary AWS credentials, supply the session token from the same provider.
cSessionToken := ""
IF (cSessionToken != "")
oRest:AddQueryParam("X-Amz-Security-Token", cSessionToken)
ENDIF
oRest:AddHeader("Content-Type", "application/json")
cResponseText := oRest:FullRequestString("POST", "/v2/email/identities", oRequest:Emit())
IF (oRest:LastMethodSuccess != 1)
? oRest:LastErrorText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
RETURN
ENDIF
IF (oRest:ResponseStatusCode == 409)
? "This identity already exists in this Region. Check its verification status."
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
RETURN
ENDIF
IF (oRest:ResponseStatusCode != 200)
? "SES returned HTTP " + Str(oRest:ResponseStatusCode) + " " + cResponseText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
RETURN
ENDIF
oResult := CreateObject("Chilkat.JsonObject")
nSuccess := oResult:Load(cResponseText)
IF (nSuccess != 1)
? oResult:LastErrorText
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
oResult:destroy()
RETURN
ENDIF
IF (oResult:BoolOf("VerifiedForSendingStatus") == 1)
? "The identity is already verified for sending."
ELSE
? "Open the verification email from AWS, follow its link, then check the identity status."
ENDIF
oRequest:destroy()
oHost:destroy()
oSigner:destroy()
oConnection:destroy()
oRest:destroy()
oResult:destroy()