いつもお世話になっております。
springframeworkでメール機能実装しており、質問があります。
下記の通りに
html
1First.html 2 <form action="/mailsend" method="POST"> 3 <button>メール送信</button> 4 </form>
でメール送信ボタンを押下した際、指定したメールアドレスにメールを送る機能を
実装しております。
しかし、メール送信ボタンを押下してもメールが送信されません。
原因が不明ですのでご教授宜しくお願いします。
下記がメール送信するためのjavaソースとなります。
java
1Mailsend.java 2package com.tuyano.springboot.mail; 3 4import org.springframework.beans.factory.annotation.Autowired; 5import org.springframework.beans.factory.annotation.Value; 6import org.springframework.mail.SimpleMailMessage; 7import org.springframework.stereotype.Component; 8import org.springframework.web.bind.annotation.RequestMapping; 9import org.springframework.web.bind.annotation.RequestMethod; 10import org.springframework.web.bind.annotation.RestController; 11import org.springframework.mail.MailSender; 12 13@RestController 14public class MailSend { 15//送信先のメールアドレス 16@Value("${spring.mail.username}") 17private String mailFrom; 18@Autowired 19MailSender mailSender; 20//メール送信メソッド 21@RequestMapping(path = "/mailsend", method = RequestMethod.POST) 22public void sendMail(){ 23SimpleMailMessage mailmsg = new SimpleMailMessage(); 24 mailmsg.setFrom(mailFrom); 25 mailmsg.setTo("送信するメールアドレス"); 26 mailmsg.setSubject("テストメール");//タイトルの設定 27 mailmsg.setText("Spring Boot より本文送信"); //本文の設定 28 mailSender.send(mailmsg); 29} 30} 31
java
1Securityconfig.java 2package com.tuyano.springboot.springsecurity; 3 4import org.springframework.context.annotation.Bean; 5import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 11import javax.sql.DataSource; 12 13import org.springframework.beans.factory.annotation.Autowired; 14import org.springframework.beans.factory.annotation.Qualifier; 15 16 17 18@EnableWebSecurity 19public class SecurityConfig extends WebSecurityConfigurerAdapter{ 20 @Autowired 21 private DataSource dataSource; 22 23 private static final String USER_QUERY="select name, password, 1 from Newaccount where name = ?"; 24 private static final 25 String ROLES_QUERY="select username, authority from AUTHORITIES where username = ?"; 26 27 @Override 28 protected void configure(HttpSecurity http) throws Exception{ 29 http 30 .authorizeRequests() 31 .antMatchers("/First.html").permitAll() 32 .antMatchers("/sucess.html").permitAll() 33 .antMatchers("/failure.html").permitAll() 34 .antMatchers("/mailsend.html").permitAll() 35 .antMatchers("/js/**").permitAll() 36 .antMatchers("/templates/**").hasAnyAuthority("ROLE_ADMIN") 37 .anyRequest().authenticated() 38 .and() 39 .formLogin() 40 .loginPage("/First.html") 41 .loginProcessingUrl("/processLogin") 42 .defaultSuccessUrl("/sucess.html") 43 .failureUrl("/failure.html") 44 .usernameParameter("name") 45 .passwordParameter("password") 46 .and() 47 .logout() 48 .logoutUrl("/processLogout") 49 .logoutSuccessUrl("/First.html") 50 .and() 51 .csrf() 52 .disable(); 53 54 } 55 @Override 56 public void configure(AuthenticationManagerBuilder auth) throws Exception { 57 auth.jdbcAuthentication() 58 .dataSource(dataSource) 59 .usersByUsernameQuery(USER_QUERY) 60 .authoritiesByUsernameQuery(ROLES_QUERY); 61 //passwordEncoder(new BCryptPasswordEncoder()); 62 //.authoritiesByUsernameQuery( 63 // "select mail_address, role from accounts where mail_address = ?"); 64 } 65 66 67} 68
html
1mailsend.html 2<!DOCTYPE html> 3<html xmlns:th="http://www.thymeleaf.org"> 4<head> 5<title>top page</title> 6<meta http-equiv="Content-Type" 7content="text/html" charset="UTF-8"/> 8 9<!-- css --> 10 11<style> 12 html { height: 100% } 13 body { height: 100%; margin: 0; padding: 0 } 14 #map { height: 100% } 15</style> 16</head> 17<body> 18<h1>メール送信完了</h1> 19 <form action="/mailsend" method="POST"> 20 <button>メール送信</button> 21 </form> 22</body> 23</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/24 12:35
2017/06/24 12:36
2017/06/25 01:40
2017/06/25 05:34
2017/06/25 10:01
2017/07/01 07:24
2017/07/04 04:08
2017/07/04 05:19
2017/07/09 02:00
2017/07/09 02:01