Streamlining Local SMTP Email Testing with MailTrap and Spring Boot

Manpreet Singh
2 min readMay 30

Local SMTP email testing is an essential part of software development to ensure the proper functioning of email notifications without sending them to real recipients. MailTrap provides a simulated SMTP server for testing email functionality. In this article, we will explore how to integrate MailTrap with a Spring Boot application to facilitate local SMTP email testing.


Before proceeding, ensure that you have the following prerequisites in place:

  1. Java Development Kit (JDK) installed on your machine.
  2. Spring Boot project setup.
  3. A MailTrap account. Sign up at if you haven’t already.

Setting up MailTrap:

  1. Sign in to your MailTrap account.
  2. Create a new Inbox within MailTrap to simulate an email environment for testing.
  3. Take note of the SMTP settings provided by MailTrap, including the SMTP hostname, port number, username, and password.

Configuring Spring Boot Project:

  1. Open your Spring Boot project in your preferred IDE.
  2. Add the necessary dependencies to your project’s pom.xml file:

3. Configure the MailTrap SMTP settings in the file:

Implementing Spring Boot Code:

  1. Create a new Java class, such as EmailService, responsible for sending emails:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

public class EmailService {

private final JavaMailSender mailSender;

public EmailService(JavaMailSender mailSender) {
this.mailSender = mailSender;

public void sendTestEmail() {
SimpleMailMessage message = new…
Manpreet Singh

Software developer who loves writing about programming, technology, passive income strategies etc.