2017-06-26 1 views
-3

私はFrom/Tp Inputフィールドを持つフォームとTextAreaをBoxとして持っています。私はSpring Bootを使用してEmailを送信したい。 Springブートを使用して電子メールを送信するにはどうすればよいですか?春のブートでメールを送信

ありがとうございました。

+2

アドバンスのおかげではないでしょう助けてください。試してみたコードを表示してください。エラーを助けることができます –

+2

これをチェックしましたか:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html? –

答えて

0

それが今

を正常に動作します私の財産である私のサービス

@Component 
public class MailService { 
    @Autowired 
    private JavaMailSender javaMailSender; 

    public void sendMail(String covere) throws MailException{ 

     SimpleMailMessage mail = new SimpleMailMessage(); 
     mail.setTo("[email protected]"); 
     mail.setFrom("[email protected]"); 
     mail.setSubject("Test"); 
     mail.setText(covere); 
     javaMailSender.send(mail); 
    } 

} 

である私のコントローラ

@Controller 
@RequestMapping("/sendmail") 
public class MailController { 
    @Autowired 
    private MailService mailService; 


    @RequestMapping(method = RequestMethod.POST) 
    private String sendMail(HttpServletRequest request) { 
     String covere = request.getParameter("covere"); 

     try { 
      mailService.sendMail(covere); 
      return "apply"; 
     } catch (MailException e) { 
      e.printStackTrace(); 
     } 
     return "apply"; 
    } 
} 

つまりファイル

spring.mail.host = smtp.gmail.com 
spring.mail.port= 465 
spring.mail.username = [email protected] 
spring.mail.password = losangeles4004* 
send.from.email= [email protected] 
spring.mail.properties.mail.smtp.auth = true; 
spring.mail.properties.mail.smtp.starttls.enable = true 
spring.mail.properties.mail.smtp.starttls.required=true 
spring.mail.properties.mail.smtp.ssl.enable = true 
spring.mail.properties.mail.socketFactory.port=587 
spring.mail.properties.mail.socketFactory.class=javax.net.ssl.SSLSocketFactory 
spring.mail.properties.mail.socketFactory.fallback=false 
関連する問題