title: How to send email with Freemarker template in Spring Boot app?
body: <p>I am trying to send email with Freemarker template.</p>
  <p>Code:</p>
  <pre><code>public String geContentFromTemplate(Map&lt;String, Object&gt; model) throws IOException, TemplateException {
          StringWriter stringWriter = new StringWriter();
          fmConfiguration.getTemplate(&quot;email-template.ftlh&quot;).process(model, stringWriter);
          return stringWriter.getBuffer().toString();
  }
  
  public void sendEmailWithTemplate(String to, String subject, User user) {
          MimeMessage mimeMessage = mailSender.createMimeMessage();
          try {
  
              MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
  
              mimeMessageHelper.setSubject(subject);
              mimeMessageHelper.setFrom(emailFrom);
              mimeMessageHelper.setTo(to);
              Map&lt;String, Object&gt; model = new HashMap&lt;&gt;();
              model.put(&quot;firstName&quot;, user.getFirstName());
              model.put(&quot;lastName&quot;, user.getLastName());
              String content = geContentFromTemplate(model);
              mimeMessageHelper.setText(content, true);
  
              mailSender.send(mimeMessageHelper.getMimeMessage());
          } catch (MessagingException | IOException | TemplateException e) {
              e.printStackTrace();
          }
      }
  
  </code></pre>
  <p>Freemarker Bean:</p>
  <pre><code> @Bean
      public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
          FreeMarkerConfigurationFactoryBean fmConfigFactoryBean = new FreeMarkerConfigurationFactoryBean();
          fmConfigFactoryBean.setTemplateLoaderPath(&quot;classpath:templates/email-template.ftlh&quot;);
          return fmConfigFactoryBean;
      }
  </code></pre>
  <p>My template is located in Spring Boot application: <code>resources/templates/email-template.ftlh</code></p>
  <p>I receive this exception:
  <code>freemarker.template.TemplateNotFoundException: Template not found for name &quot;email-template.ftlh&quot;. The name was interpreted by this TemplateLoader: org.springframework.ui.freemarker.SpringTemplateLoader@33cceeb3.</code></p>