@Test public void sendInlineMail() throws Exception { MailBean mailBean = new MailBean(); mailBean.setRecipient("15079150591@163.com"); mailBean.setSubject("测试SpringBoot发送带静态资源邮件"); mailBean.setContent("测试SpringBoot发送带静态资源邮件，正文部分"); mailUtil.sendInlineMail(mailBean); }
public void sendInlineMail(MailBean mailBean) { MimeMessage mimeMailMessage = null; try { mimeMailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); mimeMessageHelper.setFrom(MAIL_SENDER); mimeMessageHelper.setTo(mailBean.getRecipient()); mimeMessageHelper.setSubject(mailBean.getSubject()); mimeMessageHelper.setText("<html><body>带静态资源的邮件内容，这个一张IDEA配置的照片:<img src='cid:picture' /></body></html>", true); FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/mail.png")); mimeMessageHelper.addInline("picture", file); javaMailSender.send(mimeMailMessage); } catch (Exception e) { logger.error("邮件发送失败", e.getMessage()); } }
MailUtil { public void sendInlineMail(MailBean mailBean) { MimeMessage mimeMailMessage = null; try { mimeMailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); mimeMessageHelper.setFrom(MAIL_SENDER); mimeMessageHelper.setTo(mailBean.getRecipient()); mimeMessageHelper.setSubject(mailBean.getSubject()); mimeMessageHelper.setText("<html><body>带静态资源的邮件内容，这个一张IDEA配置的照片:<img src='cid:picture' /></body></html>", true); FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/mail.png")); mimeMessageHelper.addInline("picture", file); javaMailSender.send(mimeMailMessage); } catch (Exception e) { logger.error("邮件发送失败", e.getMessage()); } } }
MailUtil { public void sendInlineMail(MailBean mailBean) { MimeMessage mimeMailMessage = null; try { mimeMailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); mimeMessageHelper.setFrom(MAIL_SENDER); mimeMessageHelper.setTo(mailBean.getRecipient()); mimeMessageHelper.setSubject(mailBean.getSubject()); mimeMessageHelper.setText("<html><body>带静态资源的邮件内容，这个一张IDEA配置的照片:<img src='cid:picture' /></body></html>", true); FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/mail.png")); mimeMessageHelper.addInline("picture", file); javaMailSender.send(mimeMailMessage); } catch (Exception e) { logger.error("邮件发送失败", e.getMessage()); } }  }
MailUtil { public void sendInlineMail(MailBean mailBean) { MimeMessage mimeMailMessage = null; try { mimeMailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); mimeMessageHelper.setFrom(MAIL_SENDER); mimeMessageHelper.setTo(mailBean.getRecipient()); mimeMessageHelper.setSubject(mailBean.getSubject()); mimeMessageHelper.setText("<html><body>带静态资源的邮件内容，这个一张IDEA配置的照片:<img src='cid:picture' /></body></html>", true); FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/mail.png")); mimeMessageHelper.addInline("picture", file); javaMailSender.send(mimeMailMessage); } catch (Exception e) { logger.error("邮件发送失败", e.getMessage()); } }  void sendSimpleMail(MailBean mailBean); void sendHTMLMail(MailBean mailBean); void sendAttachmentMail(MailBean mailBean); void sendInlineMail(MailBean mailBean); void sendTemplateMail(MailBean mailBean); void sendMailByQueue(MailBean mailBean); }
MailUtil { public void sendInlineMail(MailBean mailBean) { MimeMessage mimeMailMessage = null; try { mimeMailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMailMessage, true); mimeMessageHelper.setFrom(MAIL_SENDER); mimeMessageHelper.setTo(mailBean.getRecipient()); mimeMessageHelper.setSubject(mailBean.getSubject()); mimeMessageHelper.setText("<html><body>带静态资源的邮件内容，这个一张IDEA配置的照片:<img src='cid:picture' /></body></html>", true); FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/mail.png")); mimeMessageHelper.addInline("picture", file); javaMailSender.send(mimeMailMessage); } catch (Exception e) { logger.error("邮件发送失败", e.getMessage()); } }  void sendSimpleMail(MailBean mailBean); void sendHTMLMail(MailBean mailBean); void sendAttachmentMail(MailBean mailBean); void sendInlineMail(MailBean mailBean); void sendTemplateMail(MailBean mailBean); void sendMailByQueue(MailBean mailBean);  }