Skip to content

Commit

Permalink
different results while sending mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 30, 2023
1 parent 69b4db4 commit 6a8e7cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static enum STATUS {
NEW,
IN_PROGRESS,

TEMPORARY_FAILED,

FINALLY_FAILED,

DONE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.MailAuthenticationException;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static net.dancier.kikeriki.adapter.out.mail.MailOutboxJpaEntity.STATUS.*;

@RequiredArgsConstructor
@Component
public class SendMailJob {
Expand All @@ -31,12 +35,19 @@ public void sendMails() {
}
}

@Transactional
private void sendMail(MailOutboxJpaEntity item) {
log.info("Sending the mail via SMTP: {}", item);
log.info("And sender: {}", javaMailSender);
javaMailSender.send(item.getEmailSendingRequestedEvent());
item.setStatus(MailOutboxJpaEntity.STATUS.DONE);
try {
javaMailSender.send(item.getEmailSendingRequestedEvent());
item.setStatus(DONE);
} catch (MailAuthenticationException mailAuthenticationException) {
item.setStatus(TEMPORARY_FAILED);
log.error("Problem with password." + mailAuthenticationException);
} catch (MailException mailException) {
item.setStatus(FINALLY_FAILED);
log.error("Some: " + mailException);
}
mailOutboxJpaRepository.save(item);
}

Expand Down

0 comments on commit 6a8e7cc

Please sign in to comment.