2017-03-10 1 views
0

Spring Initializer, Tomcat, Thymeleaf 템플릿 엔진 및 패키지를 실행 가능한 JAR 파일로 사용하여 Spring Boot 웹 애플리케이션을 생성했습니다. 사용SpringBoot에서 JavaMailSender 사용하기

기술 :

봄 부팅 1.4.2.RELEASE, 봄 4.3.4.RELEASE, Thymeleaf 2.1.5.RELEASE, 톰캣 삽입 8.5.6, 메이븐 3, 자바 (8) 나 '

이메일

@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 -> { 
      MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage); 
      messageHelper.setFrom("[email protected]"); 
      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()); 
     } 
    } 
} 

을 보내이 서비스를 생성하지만이 오류가 발생했습니다했습니다 때 SpringBootApplication 초기화

*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

Binding to target [email protected]d11 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 

이것은 내 application.properties입니다.

spring.mail.host=localhost 
spring.mail.port=25 
spring.mail.username= 
spring.mail.password= 
spring.mail.protocol=smtp 
spring.mail.defaultEncoding=UTF-8 

답변

1

속성과 같은 줄에 주석을 사용할 수 없습니다. Everycomment는 오류 메시지가

Value: 25 # SMTP server port 

그래서 값이 문자열 '25 # SMTP 서버 포트 '와 정수로 변환 할 수 없습니다 보여줍니다'#의 ' 로 시작하는 한 줄에 있어야합니다.

은 재산보다, 자신의 라인에 주석을 이동

:

# SMTP server port 
spring.mail.port=25 
관련 문제