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

Fix email FROM address to ensure it matches SMTP username #290

Merged
merged 1 commit into from
Aug 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class EmailService implements NotificationDispatcher {
private final TemporaryPasswordService temporaryPasswordService;
private final String contactEmail;
private final boolean enabled;
private final String from;
private final Logger logger = LoggerFactory.getLogger(EmailService.class);


Expand All @@ -39,13 +40,15 @@ public class EmailService implements NotificationDispatcher {
public EmailService(JavaMailSender emailSender, SpringTemplateEngine templateEngine, OtpService otpService,
TemporaryPasswordService temporaryPasswordService,
@Value("${server.owner.contact}") String contactEmail,
@Value("${spring.mail.host}") String smtpHost) throws EmailException {
@Value("${spring.mail.host}") String smtpHost,
@Value("${spring.mail.username}") String from) throws EmailException {
this.emailSender = emailSender;
this.templateEngine = templateEngine;
this.otpService = otpService;
this.temporaryPasswordService = temporaryPasswordService;
this.contactEmail = contactEmail;
this.enabled = Strings.isNotEmpty(smtpHost);
this.from = from;
if (isEnabled()) {
checkConnection();
}
Expand Down Expand Up @@ -230,6 +233,7 @@ private MimeMessageHelper createMessageHelper(MimeMessage mimeMessage, String to
helper = new MimeMessageHelper(mimeMessage, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setFrom(from);
} catch (MessagingException e) {
logger.error("Error while setting mail to send", e);
throw new EmailException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EmailServiceUnitTests {
private Transport transport;
@Mock
private MimeMessage mimeMessage;
private final String from = "test@test.com";
private EmailService emailService;


Expand All @@ -41,7 +42,7 @@ void setup() throws EmailException, NoSuchProviderException {
//Mockito.when(session.getTransport("smtp")).thenReturn(transport);
Mockito.when(emailSender.createMimeMessage()).thenReturn(mimeMessage);
emailService =
new EmailService(emailSender, templateEngine, otpService, temporaryPasswordService, "contact", "smtp");
new EmailService(emailSender, templateEngine, otpService, temporaryPasswordService, "contact", "smtp", from);
}


Expand Down
Loading