source: phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/EmailService.java

Last change on this file was dfd5d87, checked in by Marko <Marko@…>, 2 years ago

Registration logic with confirmation token implemented

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package finki.it.phoneluxbackend.services;
2
3import finki.it.phoneluxbackend.security.email.EmailSender;
4import lombok.AllArgsConstructor;
5import org.slf4j.Logger;
6import org.slf4j.LoggerFactory;
7import org.springframework.mail.javamail.JavaMailSender;
8import org.springframework.mail.javamail.MimeMessageHelper;
9import org.springframework.scheduling.annotation.Async;
10import org.springframework.stereotype.Service;
11
12import javax.mail.MessagingException;
13import javax.mail.internet.MimeMessage;
14
15@Service
16@AllArgsConstructor
17public class EmailService implements EmailSender {
18
19 private final JavaMailSender mailSender;
20 private final static Logger LOGGER = LoggerFactory.getLogger(EmailService.class);
21
22
23
24 @Override
25 @Async
26 public void send(String to, String email) {
27 try{
28 MimeMessage mimeMessage = mailSender.createMimeMessage();
29 MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,"utf-8");
30 helper.setText(email,true);
31 helper.setTo(to);
32 helper.setSubject("Confirm your email - Phonelux");
33 helper.setFrom("phonelux_official@gmail.com");
34 mailSender.send(mimeMessage);
35 } catch (MessagingException e){
36 LOGGER.error("Failed to send email ", e);
37 throw new IllegalStateException("Failed to send email");
38 }
39 }
40}
Note: See TracBrowser for help on using the repository browser.