Files
spring-integration-samples/basic/mail
Artem Bilan 361866da58 Move main to version 6.0
* Upgrade to the latest dependencies
* Migrate samples to `jakarta` namespace
* Rework `cafe-scripted` to RSocket instead of already removed RMI
* Migrate JMS samples to Apache Artemis for Jakarta EE 9
* Disables mails tests since there is a requirement to migrate to Greenmail for Jakarta EE 9 support
* Rework `generatePom` task to a new `maven-publish` plugin style
2022-01-20 17:10:31 -05:00
..
2019-03-22 14:52:00 -04:00
2022-01-20 17:10:31 -05:00

Mail sample

This example demonstrates the following aspects of the Mail support available with Spring Integration:

  1. IMAP IDLE Inbound Channel Adapter (with sample GMail configuration)
  2. POP3 Inbound Channel Adapter (with sample GMail configuration)

Simply change configuration file (src/main/resources/META-INF/spring/integration/gmail-imap-idle-config.xml or gmail-pop3-config.xml) to point to your existing GMail account (replace userid and password) and run:

  • GmailInboundImapIdleAdapterTest.java - for IMAP IDLE sample
  • GmailInboundPop3AdapterTest - for POP3 sample

IMPORTANT: You must enable POP3/IMAP access for your google account (follow Settings link on your GMail page).

Once started, start sending emails to your account. You'll see that adapter will receive messages and will publish them to a channel specified by 'channel' attribute.

You should see the output similar to this:

DEBUG: org.springframework.integration.mail.ImapMailReceiver - connecting to store [imaps://<your_user_name>:*****@imap.gmail.com:993/inbox]
DEBUG: org.springframework.integration.mail.ImapMailReceiver - opening folder [imaps://<your_user_name>:*****@imap.gmail.com:993/inbox]
INFO : org.springframework.integration.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX]

Send a Message and you will see:

DEBUG: org.springframework.integration.mail.ImapMailReceiver - found 2 new messages
DEBUG: org.springframework.integration.mail.ImapIdleChannelAdapter - received 2 mail messages
INFO : org.springframework.integration.samples.mail.imapidle.GmailImapIdleAdapterTest - Message: [Payload=javax.mail.internet.MimeMessage@1f00aff5][Headers={$timestamp=1284745370451, $id=9dfd4b30-2d15-4905-9301-f39aa4073ea0}]
INFO : org.springframework.integration.samples.mail.imapidle.GmailImapIdleAdapterTest - Message: [Payload=javax.mail.internet.MimeMessage@66200db9][Headers={$timestamp=1284745370452, $id=4b8322ba-f469-4afc-af4f-1332a94b735b}]
DEBUG: org.springframework.integration.mail.ImapIdleChannelAdapter - waiting for mail
DEBUG: org.springframework.integration.mail.ImapMailReceiver - opening folder [imaps://<your_user_name>:*****@imap.gmail.com:993/inbox]

You can experiment with various attributes of the adapter (e.g., should-delete-messages, should-mark-messages-as-read etc...)