1 | package it.finki.charitable.services;
|
---|
2 |
|
---|
3 | import org.springframework.mail.SimpleMailMessage;
|
---|
4 | import org.springframework.mail.javamail.JavaMailSender;
|
---|
5 | import org.springframework.stereotype.Component;
|
---|
6 |
|
---|
7 | @Component
|
---|
8 | public class EmailService {
|
---|
9 |
|
---|
10 | private final JavaMailSender javaMailSender;
|
---|
11 |
|
---|
12 | public EmailService(JavaMailSender javaMailSender) {
|
---|
13 | this.javaMailSender = javaMailSender;
|
---|
14 | }
|
---|
15 |
|
---|
16 | public void sendValidationEmail(String to, String subject, String token) {
|
---|
17 | SimpleMailMessage message = new SimpleMailMessage();
|
---|
18 | message.setTo(to);
|
---|
19 | message.setSubject(subject);
|
---|
20 |
|
---|
21 | String text = "Verify your account on the following link\n" +
|
---|
22 | "http://localhost:8080/validate?token=" + token;
|
---|
23 | message.setText(text);
|
---|
24 | javaMailSender.send(message);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public void sendApprovalEmail(String to, String subject, Long postId) {
|
---|
28 | SimpleMailMessage message = new SimpleMailMessage();
|
---|
29 | message.setTo(to);
|
---|
30 | message.setSubject(subject);
|
---|
31 |
|
---|
32 | String text = "Your post has been approved\n" + "http://localhost:8080/post?postid=" + postId;
|
---|
33 | message.setText(text);
|
---|
34 | javaMailSender.send(message);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void sendNoApprovalEmail(String to, String subject, String description) {
|
---|
38 | SimpleMailMessage message = new SimpleMailMessage();
|
---|
39 | message.setTo(to);
|
---|
40 | message.setSubject(subject);
|
---|
41 |
|
---|
42 | String text = "Sorry, your post hasn't been approved\n" +
|
---|
43 | "Moderator:\n" + description;
|
---|
44 | message.setText(text);
|
---|
45 | javaMailSender.send(message);
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void sendDeletionEmail(String to, String subject, String description) {
|
---|
49 | SimpleMailMessage message = new SimpleMailMessage();
|
---|
50 | message.setTo(to);
|
---|
51 | message.setSubject(subject);
|
---|
52 |
|
---|
53 | String text = "Sorry, your post has been deleted\n" +
|
---|
54 | "Moderator:\n" + description;
|
---|
55 | message.setText(text);
|
---|
56 | javaMailSender.send(message);
|
---|
57 | }
|
---|
58 | }
|
---|