Skip to content
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
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ JWT_SECRET=local-dev-secret-please-change-this-for-production-use-only
# all other features work without mail configuration.
# Use a Gmail App Password (not your real account password):
# https://myaccount.google.com/apppasswords
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_USERNAME=noreply.iksys@gmail.com
MAIL_PASSWORD=sxxiiqtdxgkulkqy
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,36 @@ private void sendInviteEmail(User user, String token) {
+ inviteLink + "\n\n"
+ "This link expires in 24 hours and can only be used once.\n");

if (mailSender.isEmpty()) {
if (mailSender.isEmpty() || !isMailConfigured()) {
logger.warn("Mail sender not configured — invite email NOT sent to userId={} email={}", user.getId(), user.getEmail());
logger.info("Invite link for userId={}: {}", user.getId(), inviteLink);
return;
}
mailSender.get().send(message);
logger.info("Invite email sent to userId={} email={}", user.getId(), user.getEmail());

try {
mailSender.get().send(message);
logger.info("Invite email sent to userId={} email={}", user.getId(), user.getEmail());
} catch (Exception ex) {
logger.error("Failed to send invite email to userId={} email={}: {}",
user.getId(), user.getEmail(), ex.getMessage());
}
}

/**
* Returns true only if mail credentials are actually provided.
* Spring auto-configures a JavaMailSender even with empty username/password,
* which causes SMTP connections to hang. This guard prevents that.
*/
private boolean isMailConfigured() {
if (mailSender.isEmpty()) {
return false;
}
// If the sender is a JavaMailSenderImpl, verify credentials are present
if (mailSender.get() instanceof org.springframework.mail.javamail.JavaMailSenderImpl impl) {
String username = impl.getUsername();
return username != null && !username.isBlank();
}
return true;
}

private String generateToken() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void updateCurrentOrganizationSavesChangesBeforeMappingResponse() {
when(accessContext.getCurrentOrganizationId()).thenReturn(100L);
when(organizationRepository.findById(100L)).thenReturn(Optional.of(existing));
when(organizationRepository.existsByOrganizationNumberAndIdNot("987654321", 100L)).thenReturn(false);
when(organizationRepository.save(existing)).thenReturn(existing);
when(organizationMapper.toResponse(existing)).thenReturn(response);

OrganizationResponse result = organizationService.updateCurrentOrganization(request);
Expand Down
Loading