添加发送人

Posted 宋不争

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加发送人相关的知识,希望对你有一定的参考价值。

public void sendEmail() {
        Properties properties = new Properties();
        properties.setProperty("cc", "aaa;mike;don");
        properties.setProperty("ccAdd", "nogsvr;jsgvsrj");
        properties.setProperty("ccGroup", "g_D1;g_D2");


        String[] cc = Optional.ofNullable(properties.getProperty(OperationDaily.CC)).orElse("no").split(OperationDaily.SEMICOLON);
        String[] ccGroup = Optional.ofNullable(properties.getProperty(OperationDaily.CC_GROUP)).orElse("no").split(OperationDaily.SEMICOLON);
        log.info("cc:{}", Arrays.toString(cc));
        log.info("ccGroup:{}", Arrays.toString(ccGroup));

        String[] actualCc;
        if (getWeekOfDate() == 6) {
            String[] ccAdd = Optional.ofNullable(properties.getProperty(OperationDaily.CC_ADD)).orElse("no").split(OperationDaily.SEMICOLON);
            log.info("ccAdd:{}", Arrays.toString(ccAdd));
            actualCc = getActualCc(cc, ccGroup, ccAdd);
        } else {
            actualCc = getActualCc(cc, ccGroup, null);
        }

        if (actualCc == null) {
            log.info("actualCc==null");
        }
        if (actualCc.length == 0) {
            log.info("actualCc==0");
        }
        if (actualCc.length == 1) {
            log.info("actualCc==1");
        }

        log.info("真实发送人:{}", Arrays.toString(actualCc));
    }

    public String[] getActualCc(String[] cc, String[] ccGroup, String[] ccAdd) {
        List<String> result = new ArrayList<>();

        // 首先拼接ccGroup
        if (ccGroup != null && ccGroup.length > 0 && !ccGroup[0].equals("no")) {
            Collections.addAll(result, ccGroup);
        }

        // 然后拼接ccAdd
        if (ccAdd != null && ccAdd.length > 0 && !ccAdd[0].equals("no")) {
            Collections.addAll(result, ccAdd);
        }

        // 最后拼接cc
        if (cc != null && cc.length > 0 && !cc[0].equals("no")) {
            Collections.addAll(result, cc);
        }
        return result.toArray(new String[0]);
    }

    public static int getWeekOfDate() {
        Date dt = new Date();
        Integer[] weekDays = {7, 1, 2, 3, 4, 5, 6};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

以上是关于添加发送人的主要内容,如果未能解决你的问题,请参考以下文章

我应该如何使用 Outlook 发送代码片段?

800人代运营公司被查封,你家的代运营公司靠得住吗?

在通知单击时将项目添加到片段内的 recyclerview

本人简历

springboot实现短信验证码的发送

代理模式