springboot-异步、发送邮件(二)

@Test   //发送复杂邮件
    void contextLoads2() throws MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        //组装
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
        //正文
        helper.setSubject("xxx你好啊");
        helper.setText("<h1 style='color:red'>java这条路行下去</h1>",true);
        //附件
        helper.addAttachment("卡伊娃.jpg",new File("C:\Users\pc\Desktop\favicon.ico"));
        helper.addAttachment("莱纳德.jpg",new File("C:\Users\pc\Desktop\favicon.ico"));

        helper.setTo("110xxxxxx56@qq.com");
        helper.setFrom("1102xxxxx56@qq.com");
        mailSender.send(mimeMessage);
    }
原文地址:https://www.cnblogs.com/shiguanzui/p/11973173.html