Java:通过邮件从数据库发送许多项目

时间:2018-07-23 16:09:22

标签: email javamail

public void sendMail( List<problem> listproblem) {

    try {
        ......

        EmailMessage msg = new EmailMessage(emailService);  
        BufferedReader br = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("../../../../../email_template/mail_template.html")));   
        StringBuilder stb = new StringBuilder();
        String line = "";


        for (int item = 1; item < listproblem.size(); item++) {
            while ((line = br.readLine()) != null) {

                if (line.contains("--Costumer--")) {
                    line = line.replace("--Costumer--", listproblem.get(item).getCustomer().getName());
                }

                if (line.contains("--Country--")) {
                    line = line.replace("--Country--", listproblem.get(item).getCustomer().getCountry().getName());
                }

                if (line.contains("--issue--")) {
                    line = line.replace("--issue--", listproblem.get(item).getName());
                }   

                if (line.contains("--Summary--")) {
                    line = line.replace("--Summary--", listproblem.get(item).getSummary());
                }  

                if (line.contains("--severity--")) {

                    if (listIssue.get(item).getPriority().contains("1")) {
                        line = line.replace("--severity--", "<label style=\"color:orange;\">Priority 1</label>");
                    }else{
                        line = line.replace("--severity--","<label style=\"color:#DF0101;\">Priority 0</label>");
                    }
                }
                stb.append(line).append("\n");
            }
            //stb.append(stb).append("\n");    

        }
    }

0 个答案:

没有答案