Changeset b8dc761 for src/main/java/it/finki/charitable/services
- Timestamp:
- 01/05/22 15:57:29 (3 years ago)
- Branches:
- master
- Children:
- 6fa3d09
- Parents:
- 881a233
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/services/EmailService.java
r881a233 rb8dc761 1 1 package it.finki.charitable.services; 2 2 3 import it.finki.charitable.entities.EmailMessage; 3 4 import org.springframework.mail.SimpleMailMessage; 4 5 import org.springframework.mail.javamail.JavaMailSender; 6 import org.springframework.scheduling.annotation.Async; 5 7 import org.springframework.stereotype.Component; 6 8 … … 9 11 10 12 private final JavaMailSender javaMailSender; 13 private final EmailMessageService emailMessageService; 11 14 12 public EmailService(JavaMailSender javaMailSender ) {15 public EmailService(JavaMailSender javaMailSender, EmailMessageService emailMessageService) { 13 16 this.javaMailSender = javaMailSender; 17 this.emailMessageService = emailMessageService; 14 18 } 15 19 … … 20 24 21 25 String text = "Verify your account on the following link\n" + 22 "http://localhost: 8080/validate?token=" + token;26 "http://localhost:9091/validate?token=" + token; 23 27 message.setText(text); 24 javaMailSender.send(message);28 sendMail(message); 25 29 } 26 30 … … 30 34 message.setSubject(subject); 31 35 32 String text = "Your post has been approved\n" + "http://localhost: 8080/post?postid=" + postId;36 String text = "Your post has been approved\n" + "http://localhost:9091/post?postid=" + postId; 33 37 message.setText(text); 34 javaMailSender.send(message);38 sendMail(message); 35 39 } 36 40 … … 43 47 "Moderator:\n" + description; 44 48 message.setText(text); 45 javaMailSender.send(message);49 sendMail(message); 46 50 } 47 51 … … 54 58 "Moderator:\n" + description; 55 59 message.setText(text); 56 javaMailSender.send(message); 60 sendMail(message); 61 } 62 63 @Async 64 public void sendMail(SimpleMailMessage message) { 65 try { 66 javaMailSender.send(message); 67 68 } catch (Exception e) { 69 emailMessageService.save(new EmailMessage(message.getTo()[0], message.getSubject(), message.getText())); 70 } 57 71 } 58 72 }
Note:
See TracChangeset
for help on using the changeset viewer.