Sample code for 30+ languages & platforms
Zig

SES Verify Email Identity

See more Amazon SES Examples

Verifies an email identity. This causes a confirmation email to be sent to the specified address.

See SES VerifyEmailIdentity for more information.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

    // Connect to the Amazon AWS REST server.
    // such as https://email.us-west-2.amazonaws.com/
    const b_tls = true;
    const port = 443;
    const b_auto_reconnect = true;
    try rest.connect("email.us-west-2.amazonaws.com", port, b_tls, b_auto_reconnect);

    // Provide AWS credentials for the REST call.
    const auth_aws = try chilkat.AuthAws.init();
    defer auth_aws.deinit();
    auth_aws.setAccessKey("AWS_ACCESS_KEY");
    auth_aws.setSecretKey("AWS_SECRET_KEY");
    // the region should match our URL above..
    auth_aws.setRegion("us-west-2");
    auth_aws.setServiceName("ses");

    rest.setAuthAws(auth_aws) catch {};

    rest.addQueryParam("Action", "VerifyEmailIdentity") catch {};

    // Add the email identity to be verified.
    // This causes an email to be sent to the address for the user to verify.
    rest.addQueryParam("EmailAddress", "somebody@someemailaddress.com") catch {};

    const response_xml = rest.fullRequestNoBody(alloc, "GET", "/") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // A successful response will have a status code equal to 200.
    if (rest.getResponseStatusCode() != 200) {
        std.debug.print("response status code = {d}\n", .{rest.getResponseStatusCode()});
        std.debug.print("response status text = {s}\n", .{try rest.getResponseStatusText(alloc)});
        std.debug.print("response header: {s}\n", .{try rest.getResponseHeader(alloc)});
        std.debug.print("response body: {s}\n", .{response_xml});
        return;
    }

    // Examine the successful XML response.
    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.loadXml(response_xml) catch {};
    std.debug.print("{s}\n", .{try xml.getXml(alloc)});

    // To get the RequestId
    std.debug.print("RequestId: {s}\n", .{try xml.chilkatPath(alloc, "ResponseMetadata|RequestId|*")});

    // A sample successful response:
    // <?xml version="1.0" encoding="utf-8" ?>
    // <VerifyEmailAddressResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
    //     <ResponseMetadata>
    //         <RequestId>b75924d3-8b61-11e6-877f-2bec40022965</RequestId>
    //     </ResponseMetadata>
    // </VerifyEmailAddressResponse>
    //
}