0

我正在尝试从 GetIdentityMailFromDomainAttributesResponse 的对象中获取“mailFromDomain”、“mailFromDomainStatusAsString”和“behaviorOnMXFailureAsString”的值。

我为此使用 AWS SDK for Java 2。

我的代码是 -

    public static Map<String, Object> getMailFromDomainSetting(String accessKeyId, String secretAccessKey,
        String region, String from) {
    logger.info("[------------] EmailUtility- getMailFromDomainSetting() senderDomain/from : "+from);
    SesClient ses = getClientObject(accessKeyId, secretAccessKey, region);
    GetIdentityMailFromDomainAttributesRequest request2 = GetIdentityMailFromDomainAttributesRequest.builder().identities(from).build();
    GetIdentityMailFromDomainAttributesResponse response2 = ses.getIdentityMailFromDomainAttributes(request2);
    Map<String, IdentityMailFromDomainAttributes> mailFromDomainAttributes = response2.mailFromDomainAttributes();
    logger.info("[------------] mailFromDomainAttributes.keySet() : "+mailFromDomainAttributes.keySet());
    for(String key : mailFromDomainAttributes.keySet()) {
        logger.info("[------------] mailFromDomainAttributes key : "+key+", value.mailFromDomain() : "+mailFromDomainAttributes.get(key).mailFromDomain());
        logger.info("[------------] mailFromDomainAttributes key : "+key+", value.mailFromDomainStatusAsString() : "+mailFromDomainAttributes.get(key).mailFromDomainStatusAsString());
        logger.info("[------------] mailFromDomainAttributes key : "+key+", value.behaviorOnMXFailureAsString() : "+mailFromDomainAttributes.get(key).behaviorOnMXFailureAsString());
    }
    Map<String, Object> map = new HashMap<>();
    mailFromDomainAttributes.entrySet().stream().map((entrySet) -> {
        String key = entrySet.getKey();
        IdentityMailFromDomainAttributes value = entrySet.getValue();
        map.put(key, key);
        map.put("mailFromDomain", value.mailFromDomain());
        return value;
    }).map((value) -> {
        map.put("mailFromDomainStatus", value.mailFromDomainStatusAsString());
        return value;
    }).forEach((value) -> {
        map.put("behaviorOnMXFailure", value.behaviorOnMXFailureAsString());
    });
    return map;
}

创建 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;
}

重要链接是 - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpointemail/model/MailFromAttributes.html公共最终字符串 mailFromDomainStatusAsString()

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-mx-record.html

4

0 回答 0