Spring Boot
Spring Boot's mail starter reads five properties — point them at a sandbox.
Before you start
- Spring Boot 2.7 or later
- spring-boot-starter-mail
1Add the starter
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
2Configure the mail sender
spring.mail.host=smtp.mailclutch.com spring.mail.port=587 spring.mail.username=mc_0000000000000000 spring.mail.password=pw_0000000000000000 spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true
Put it in application-staging.properties if your production profile has its own mail server.
3Send a test message
@Autowired private JavaMailSender mailSender; public void sendTest() { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("staging@example.com"); message.setTo("anyone@example.com"); message.setSubject("Sandbox check"); message.setText("Hello from Spring Boot."); mailSender.send(message); }
Watch it land
Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.
Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.
Awaiting your email
Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.
What usually goes wrong
@Async swallows the send
A mail method annotated
@Asyncfails on another thread — the exception never reaches your request. Send synchronously while you are checking the setup.YAML instead
The same keys nest under
spring: mail:inapplication.yml; the SMTP extras go underproperties: mail.smtp.*.
Other stacks
The same four values in another dialect. Every guide below is filled in with the sandbox pair at the top of this page.
Frameworks and languages
- LaravelFive .env variables, no package
- SymfonyOne MAILER_DSN
- DjangoFive settings, nothing installed
- RailsAction Mailer smtp_settings
- Node.jsA Nodemailer transport
- Next.jsRoute Handler or Server Action
- Gonet/smtp, standard library
- JavaJakarta Mail, no framework
- .NETMailKit: connect, auth, send
- PHPPHPMailer, no framework
- Pythonsmtplib, standard library
- Rustlettre over a STARTTLS relay