电子邮件验证和电子邮件验证状态中的 AWS SES 错误

问题描述

我将 AWS 开发工具包版本 2.x 用于 SES。 我想知道电子​​邮件的验证状态,并在未验证的情况下验证该电子邮件

收到错误“我们计算的请求签名与您提供的签名不匹配。检查您的 AWS 秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。”在下面的方法中。

我就是用这个方法来创建SesClient的对象-

    public static SesClient getClientObject(String accessKeyId,String secretAccessKey,String region) {
    AwsBasicCredentials credential = AwsBasicCredentials.create(accessKeyId,secretAccessKey);
    StaticCredentialsProvider credentialProvider = StaticCredentialsProvider.create(credential);
    SesClient amazonSimpleEmailService = SesClient.builder().credentialsProvider(credentialProvider).region(Region.of(region)).build();
    return amazonSimpleEmailService;
}

方法用于获取 emailAddress 的验证状态。参数“address”是电子邮件地址。

public static boolean isEmailAddressisverified(String accessKeyId,String region,String address) {
    SesClient ses = getClientObject(accessKeyId,secretAccessKey,region);
    ListVerifiedEmailAddressesResponse verifiedEmails = ses.listVerifiedEmailAddresses();    // getting the above error in this line
    return verifiedEmails.verifiedEmailAddresses().contains(address);
}

还有这个方法来验证emailAddress。

    public static Map<String,String> verifyEmailAddress(String accessKeyId,String address) {
    Map<String,String> returnMap = new HashMap<>();
    SesClient ses = getClientObject(accessKeyId,region);
    ListVerifiedEmailAddressesResponse verifiedEmails = ses.listVerifiedEmailAddresses();
    if (verifiedEmails.verifiedEmailAddresses().contains(address)) {
        return null;
    }
    VerifyEmailAddressResponse result = ses
            .verifyEmailAddress(VerifyEmailAddressRequest.builder().emailAddress(address).build());
    logger.debug("Verify Email Response Metadata {}",result.responseMetadata());
    logger.debug("Verify Email Response Metadata {}",result.responseMetadata().requestId());
    returnMap.put("STATUS","SUCCESS");
    returnMap.put("AWS_REQUEST_ID",result.responseMetadata().requestId());
    return returnMap;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)