This Spring Boot project provides a robust and asynchronous solution for receiving and processing emails using the JavaMail and Spring Integration frameworks.
The application's behavior and settings can be configured through the application.yml file. Key configuration parameters include:
Adjust the log levels for different packages to control the verbosity of logging.
logging:
level:
root: INFO
com.bezzine: DEBUG
org.springframework.integration: DEBUGConfigure the IMAP mail server settings, including SSL, host, port, username, and password.
mail:
imap:
ssl: true
host: imap.gmail.com
port: 993
username: your-email%40gmail.com
password: your-passwordFine-tune the task execution settings, such as thread pool size and scheduling.
spring:
task:
execution:
thread-name-prefix: autohost-task-
pool:
core-size: 2
max-size: 200
queue-capacity: 10000
scheduling:
thread-name-prefix: mail-receiver-
pool:
size: 2The ReceiveMailServiceImpl class implements the ReceiveMailService interface and provides the core functionality for handling received emails.
Key methods include:
Processes the received email, extracts information, and triggers further actions.
Fetches details of messages in the specified mail folder.
Copies the processed email to a "downloaded" folder.
Extracts information from the MIME message, displays content, and downloads attachments.
Logs basic information about the email content.
Downloads attachment files and saves them to a specified folder.
The MailReceiverConfiguration class configures the Spring Integration components for receiving emails.
Key methods include:
Invoked when a new email is received, delegates the handling to the ReceiveMailService.
Configures the default message channel for email reception.
Configures the mail receiving message source with a specified MailReceiver.
Configures the IMAP mail receiver with the necessary properties.
The AsyncConfiguration class configures asynchronous task execution using Spring's ThreadPoolTaskExecutor.
The project relies on several dependencies, including Spring Boot, Spring Integration, Spring Mail, and other utility libraries. Notable dependencies include:
spring-boot-starter-data-jpaspring-boot-starter-webspring-boot-starter-mailspring-integration-mailcommons-iocommons-lang3commons-email
To build and run the application, use the provided Maven configuration. The main class to execute is MailboxAutomationApplication.
./mvnw spring-boot:run- This application is built with Spring Boot 3.2.1 and Java 17.
- Ensure that the necessary dependencies are available and configured in the
pom.xmlfile.