title: Using JavaMailSender in SpringBoot
body: <p>I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.</p>
  
  <p>Technologies used:</p>
  
  <p>Spring Boot 1.4.2.RELEASE, Spring 4.3.4.RELEASE, Thymeleaf 2.1.5.RELEASE, Tomcat Embed 8.5.6, Maven 3, Java 8</p>
  
  <p>I've created this service to send emails</p>
  
  <pre><code>@Service
  public class MailClient {
  
      protected static final Logger looger = LoggerFactory.getLogger(MailClient.class);
  
      @Autowired
      private JavaMailSender mailSender;
  
      private MailContentBuilder mailContentBuilder;
  
      @Autowired
      public MailClient(JavaMailSender mailSender, MailContentBuilder mailContentBuilder) {
          this.mailSender = mailSender;
          this.mailContentBuilder = mailContentBuilder;
      }
  
      //TODO: in a properties
      public void prepareAndSend(String recipient, String message) {
          MimeMessagePreparator messagePreparator = mimeMessage -&gt; {
              MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
              messageHelper.setFrom("nunito@calzada.com");
              messageHelper.setTo(recipient);
              messageHelper.setSubject("Sample mail subject");
              String content = mailContentBuilder.build(message);
              messageHelper.setText(content, true);
          };
          try {
              if (looger.isDebugEnabled()) {
                  looger.debug("sending email to " + recipient);
              }
              mailSender.send(messagePreparator);
          } catch (MailException e) {
              looger.error(e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>But I got this error when Init the SpringBootApplication</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Binding to target org.springframework.boot.autoconfigure.mail.MailProperties@1e94ed11 failed:
  
      Property: spring.mail.defaultEncoding
      Value: UTF-8 
      Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.nio.charset.Charset' for property 'defaultEncoding'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.nio.charset.Charset]
  
  
  Action:
  
  Update your application's configuration
  </code></pre>
  
  <p>and this is my application.properties</p>
  
  <pre><code>spring.mail.host=localhost
  spring.mail.port=25 
  spring.mail.username= 
  spring.mail.password= 
  spring.mail.protocol=smtp
  spring.mail.defaultEncoding=UTF-8 
  </code></pre>