Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringMail未发送html邮件的附件_Spring_Attachment - Fatal编程技术网

SpringMail未发送html邮件的附件

SpringMail未发送html邮件的附件,spring,attachment,Spring,Attachment,我正在使用SpringMail发送带有附件的html邮件,但要么html邮件正在发送,要么如果有附件,邮件会显示html代码。请告诉我这里少了什么。如果我取消对message.setContent的注释,附件将不会消失。这是我的密码: try{ MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper; try { hel

我正在使用SpringMail发送带有附件的html邮件,但要么html邮件正在发送,要么如果有附件,邮件会显示html代码。请告诉我这里少了什么。如果我取消对message.setContent的注释,附件将不会消失。这是我的密码:

try{
        MimeMessage message = mailSender.createMimeMessage();

        MimeMessageHelper helper;

        try {
            helper = new MimeMessageHelper(message, true, "UTF-8");
            //message.setContent(text, "text/html");

            helper.setFrom(from);
            helper.setTo(to);
            helper.setSubject(subject);
            helper.setText(text);

            if(hasAttachment){
                FileSystemResource file = new FileSystemResource(filePath);

                helper.addAttachment(fileName, file);                   
            }

            mailSender.send(message);
        }
        catch(AddressException aex){
            System.out.println("Cannot send : " + aex.getMessage());
        }
        catch (Exception e) {
            System.out.println("Not sending " + e.getMessage());
        }
    }
    catch(Exception ex){
        System.out.println("Could not send : " + ex.getMessage());
    }

我成功了。删除注释行。更改:

helper.setText(文本)

helper.setText(text,true);//这里true表示HTML消息