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

 

posted @ 2019-12-02 20:43  白石雁归南  阅读(221)  评论(0编辑  收藏  举报