Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test code to debug sendmail #124

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/it/gov/innovazione/ndc/service/EmailService.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package it.gov.innovazione.ndc.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
class EmailService {

private final JavaMailSender javaMailSender;
@Value("${alerter.mail.sender}")
private final String from;
@Value("${spring.mail.properties.mail.debug:false}")
private boolean mailDebug;

void sendEmail(String to, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
Expand All @@ -23,4 +29,12 @@ void sendEmail(String to, String subject, String text) {
javaMailSender.send(message);
}

@EventListener(ApplicationStartedEvent.class)
void debugSendMail() {
if (mailDebug) {
log.info("Sending test email");
sendEmail("[email protected]", "Test", "Test");
}
}

}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ spring.mail.username=${ALERTER_SMTP_USER:[email protected]}
spring.mail.password=${ALERTER_SMTP_PASSWORD:}
spring.mail.properties.mail.smtp.auth=${ALERTER_SMTP_AUTH:true}
spring.mail.properties.mail.smtp.starttls.enable=${ALERTER_SMTP_STARTTLS:true}
spring.mail.properties.mail.smtp.ssl.enable=${ALERTER_SMTP_SSL:false}
spring.mail.properties.mail.debug=${JAVA_MAIL_DEBUG:false}
Loading