Ignore:
Timestamp:
01/05/22 15:57:29 (3 years ago)
Author:
NikolaCenevski <cenevskinikola@…>
Branches:
master
Children:
6fa3d09
Parents:
881a233
Message:

part 2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/charitable/services/EmailService.java

    r881a233 rb8dc761  
    11package it.finki.charitable.services;
    22
     3import it.finki.charitable.entities.EmailMessage;
    34import org.springframework.mail.SimpleMailMessage;
    45import org.springframework.mail.javamail.JavaMailSender;
     6import org.springframework.scheduling.annotation.Async;
    57import org.springframework.stereotype.Component;
    68
     
    911
    1012    private final JavaMailSender javaMailSender;
     13    private final EmailMessageService emailMessageService;
    1114
    12     public EmailService(JavaMailSender javaMailSender) {
     15    public EmailService(JavaMailSender javaMailSender, EmailMessageService emailMessageService) {
    1316        this.javaMailSender = javaMailSender;
     17        this.emailMessageService = emailMessageService;
    1418    }
    1519
     
    2024
    2125        String text = "Verify your account on the following link\n" +
    22                 "http://localhost:8080/validate?token=" + token;
     26                "http://localhost:9091/validate?token=" + token;
    2327        message.setText(text);
    24         javaMailSender.send(message);
     28        sendMail(message);
    2529    }
    2630
     
    3034        message.setSubject(subject);
    3135
    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;
    3337        message.setText(text);
    34         javaMailSender.send(message);
     38        sendMail(message);
    3539    }
    3640
     
    4347                "Moderator:\n" + description;
    4448        message.setText(text);
    45         javaMailSender.send(message);
     49        sendMail(message);
    4650    }
    4751
     
    5458                "Moderator:\n" + description;
    5559        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        }
    5771    }
    5872}
Note: See TracChangeset for help on using the changeset viewer.