AWS SES 获取 MAIL FROM 域状态的“失败”状态,AWS SDK for Java 2.x

问题描述

我试图从 GetIdentityMailFromDomainAttributesResponse 的对象中获取“mailFromDomain”、“mailFromDomainStatusAsstring”和“behaviorOnMXFailureAsstring”的值。

我为此使用了适用于 Java 2 的 AWS 开发工具包。

我的代码是 -

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

这方面的重要链接是 -

public final String mailFromDomainStatusAsString()

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpointemail/model/MailFromAttributes.html

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

解决方法

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

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

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