-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5af0a08
commit ad865de
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
package d00000.webapp; | |||
|
|||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.mail.MailSender; | |||
import org.springframework.mail.SimpleMailMessage; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestParam; | |||
|
|||
@Controller | |||
@RequestMapping("/mail") | |||
public class MailController { | |||
|
|||
private MailSender mailSender; | |||
|
|||
/** コンストラクタ */ | |||
public MailController(@Autowired MailSender mailSender) { | |||
this.mailSender = mailSender; | |||
} | |||
|
|||
/** メール送信フォーム */ | |||
@GetMapping("/send") | |||
public String sendGet() { | |||
return "mail/send"; | |||
} | |||
|
|||
/** メール送信処理 */ | |||
@PostMapping("/send") | |||
public String sendPost(@RequestParam("to") String to, @RequestParam("subject") String subject, | |||
@RequestParam("text") String text) { | |||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); | |||
simpleMailMessage.setTo(to); | |||
simpleMailMessage.setSubject(subject); | |||
simpleMailMessage.setText(text); | |||
this.mailSender.send(simpleMailMessage); | |||
return "redirect:/mail/send"; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
<!DOCTYPE html> | |||
<html xmlns:th="http://www.thymeleaf.org"> | |||
<head> | |||
<meta charset="UTF-8"/> | |||
<title>メール送信</title> | |||
</head> | |||
<body> | |||
<h1>メール送信サンプル</h1> | |||
<form th:action="@{/mail/send}" method="post"> | |||
<dl> | |||
<dt>to</dt> | |||
<dd><input name="to" type="email" style="width: 400px"/></dd> | |||
<dt>subject</dt> | |||
<dd><input name="subject" type="text" style="width: 400px"/></dd> | |||
<dt>text</dt> | |||
<dd><textarea name="text" style="width: 400px; height: 200px"></textarea></dd> | |||
</dl> | |||
<button type="submit">送信</button> | |||
</form> | |||
</body> | |||
</html> |