Integrating SMTP Email Delivery into Apollo Portal
To let Apollo Portal send transactional messages—such as password-reset links, account-activation tokens, or system alerts—you can wire an SMTP relay into the application. The walkthrough below assumes Spring Boot 3.x and uses the JavaMail abstraction provided by spring-boot-starter-mail.
1. Bring in the Mail Starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2. Externalize Connection Settings
Place the following keys in application.yml (or application.properties if you prefer):
spring:
mail:
host: smtp.acme.io
port: 587
username: noreply@acme.io
password: ${MAIL_PASSWORD} # Prefer an env variable or vault
properties:
mail:
smtp:
auth: true
starttls:
enable: true
ssl:
trust: smtp.acme.io
3. Programmatic Mail-Sender Bean
Create a dedicated configuration clas sothat the mail client is assembled once and reused everywhere:
@Configuration
public class SmtpConfig {
@Bean
public JavaMailSender mailSender(Environment env) {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(env.getRequiredProperty("spring.mail.host"));
sender.setPort(env.getRequiredProperty("spring.mail.port", Integer.class));
sender.setUsername(env.getRequiredProperty("spring.mail.username"));
sender.setPassword(env.getRequiredProperty("spring.mail.password"));
Properties extra = sender.getJavaMailProperties();
extra.put("mail.smtp.auth", "true");
extra.put("mail.smtp.starttls.enable", "true");
extra.put("mail.debug", "false"); // flip to true while debugging
return sender;
}
}
4. Reusable Mail Dispatch Service
Encapsulate the sending logic in a single component so controllers and schedulers can trigger emails without repeating boilerplate:
@Service
public class PortalNotifier {
private final JavaMailSender mailSender;
public PortalNotifier(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public void sendPlain(String recipient, String title, String body) {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(recipient);
msg.setSubject(title);
msg.setText(body);
mailSender.send(msg);
}
public void sendHtml(String recipient, String title, String html) throws MessagingException {
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mime, "utf-8");
helper.setTo(recipient);
helper.setSubject(title);
helper.setText(html, true);
mailSender.send(mime);
}
}
5. Hooking It into Apollo Portal
Whenever a controller needs to notify a user—e.g., after a successful password-reset request—inject PortalNotifier and call:
notifier.sendPlain(user.getEmail(),
"Reset your Apollo Portal password",
"Click the link: " + resetUrl);
The same service can be extended to support attachments, inline images, or templated HTML bodies by leveraging MimeMessageHelper and a template engine such as Thymeleaf or FreeMarker.