use of pl.pollub.cs.pentagoncafe.flare.exception.sendingEmail.SendingEmailException in project Flare-event-calendar by PollubCafe.
the class EmailSenderServiceImpl method sendEmail.
@Override
public void sendEmail(EmailToEventAuthorReqDTO emailToEventAuthorReqDTO) {
Event event = eventRepository.findById(emailToEventAuthorReqDTO.getEventID()).orElseThrow(() -> new ObjectNotFoundException(Event.class, "id", emailToEventAuthorReqDTO.getEventID()));
User eventAuthor = event.getOrganizer();
String message = emailToEventAuthorReqDTO.getContent();
String subject = emailToEventAuthorReqDTO.getSubject();
Email email = emailBuilder.buildEmailToEventAuthor(message, subject).to(eventAuthor.getEmail());
try {
checkArgument(email instanceof HtmlEmail);
emailSender.send((HtmlEmail) email);
} catch (MessagingException e) {
e.printStackTrace();
throw new SendingEmailException("Email to author sending filed.");
}
}
Aggregations