Sample code for 30+ languages & platforms
Java

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

Java
import com.chilkatsoft.chilkat2.AuthAws;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.Socket;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

        // Assumes Chilkat is unlocked. See Global Unlock Sample.

        success = false;

        // Use an address whose inbox you can open. SES sends the verification link there.
        JsonObject request = new JsonObject();
        request.updateString("EmailIdentity", "sender+reports@example.com");

        // Use the same AWS Region for the identity, endpoint, and Signature Version 4.
        String region = "us-west-2";
        StringBuilder host = new StringBuilder();
        host.append("email.");
        host.append(region);
        host.append(".amazonaws.com");

        AuthAws signer = new AuthAws();
        // Supply the credentials from your application's credential provider.
        signer.setAccessKey("AWS_ACCESS_KEY_ID");
        signer.setSecretKey("AWS_SECRET_ACCESS_KEY");
        signer.setRegion(region);
        signer.setServiceName("ses");

        Socket connection = new Socket();
        connection.setRequireSslCertVerify(true);
        try {
            connection.connect(host.getAsString(), 443, true, 10000);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        Rest rest = new Rest();
        try {
            rest.useConnection(connection, false);

            rest.setAuthAws(signer);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

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

        rest.addHeader("Content-Type", "application/json");
        String responseText;
        try {
            responseText = rest.fullRequestString("POST", "/v2/email/identities", request.emit());
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        if (rest.getResponseStatusCode() == 409) {
            System.out.println("This identity already exists in this Region. Check its verification status.");
            return;
        }

        if (rest.getResponseStatusCode() != 200) {
            System.out.println("SES returned HTTP " + rest.getResponseStatusCode() + " " + responseText);
            return;
        }

        JsonObject result = new JsonObject();
        try {
            result.load(responseText);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        if (result.boolOf("VerifiedForSendingStatus")) {
            System.out.println("The identity is already verified for sending.");
        } else {
            System.out.println("Open the verification email from AWS, follow its link, then check the identity status.");
        }
    }
}