Search in sources :

Example 1 with SendingEmailException

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.");
    }
}
Also used : User(pl.pollub.cs.pentagoncafe.flare.domain.User) Email(pl.pollub.cs.pentagoncafe.flare.component.email.Email) HtmlEmail(pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail) MessagingException(javax.mail.MessagingException) ObjectNotFoundException(pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException) HtmlEmail(pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail) Event(pl.pollub.cs.pentagoncafe.flare.domain.Event) SendingEmailException(pl.pollub.cs.pentagoncafe.flare.exception.sendingEmail.SendingEmailException)

Aggregations

MessagingException (javax.mail.MessagingException)1 Email (pl.pollub.cs.pentagoncafe.flare.component.email.Email)1 HtmlEmail (pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail)1 Event (pl.pollub.cs.pentagoncafe.flare.domain.Event)1 User (pl.pollub.cs.pentagoncafe.flare.domain.User)1 ObjectNotFoundException (pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException)1 SendingEmailException (pl.pollub.cs.pentagoncafe.flare.exception.sendingEmail.SendingEmailException)1