2018年3月22日 | Leave a comment 问题: 解决: http://idorobot.com:10080/demo/spboot-integration-mail pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>demo</groupId> <artifactId>testIngration</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-integration</artifactId> </dependency> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-mail</artifactId> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> </project> 123456789101112131415161718192021222324252627282930313233343536 <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>demo</groupId> <artifactId>testIngration</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-integration</artifactId> </dependency> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-mail</artifactId> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties></project> src/main/java/demo/testingration/App.java package demo.testingration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.integration.config.EnableIntegration; @SpringBootApplication @EnableIntegration public class App { public static void main(String[] argv){ SpringApplication.run(App.class, argv); } } 12345678910111213 package demo.testingration; import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.integration.config.EnableIntegration; @SpringBootApplication@EnableIntegrationpublic class App { public static void main(String[] argv){ SpringApplication.run(App.class, argv); }} src/main/java/demo/testingration/Job1.java package demo.testingration; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; import org.springframework.integration.dsl.Pollers; import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.integration.mail.MailReceivingMessageSource; import org.springframework.stereotype.Component; @Component @Lazy(false) public class Job1 { @Bean public ImapMailReceiver imap() { org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean d; return new ImapMailReceiver("imap://3098173057:*****@imap.qq.com/INBOX");//TODO:CHANGE PWD } @Bean public MailReceivingMessageSource imapSource(ImapMailReceiver imap) { return new MailReceivingMessageSource(imap); } @Bean public IntegrationFlow flow1(MailReceivingMessageSource imapSource) { final IntegrationFlow ret = IntegrationFlows.from(imapSource, c -> c.poller(Pollers.fixedRate(10000))) .log() .handle(msg -> { try { System.out.println("msg:" + msg); MimeMessage mimeMsg = (MimeMessage) msg.getPayload(); System.out.println("mimeMsg subject:" + mimeMsg.getSubject() + " \t content:" + mimeMsg.getContent()); } catch (MessagingException | IOException ex) { Logger.getLogger(Job1.class.getName()).log(Level.SEVERE, null, ex); } }) .get(); return ret; } } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 package demo.testingration; import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;import javax.mail.MessagingException;import javax.mail.internet.MimeMessage;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Lazy;import org.springframework.integration.dsl.IntegrationFlow;import org.springframework.integration.dsl.IntegrationFlows;import org.springframework.integration.dsl.Pollers;import org.springframework.integration.mail.ImapMailReceiver;import org.springframework.integration.mail.MailReceivingMessageSource;import org.springframework.stereotype.Component; @Component@Lazy(false)public class Job1 { @Bean public ImapMailReceiver imap() { org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean d; return new ImapMailReceiver("imap://3098173057:*****@imap.qq.com/INBOX");//TODO:CHANGE PWD } @Bean public MailReceivingMessageSource imapSource(ImapMailReceiver imap) { return new MailReceivingMessageSource(imap); } @Bean public IntegrationFlow flow1(MailReceivingMessageSource imapSource) { final IntegrationFlow ret = IntegrationFlows.from(imapSource, c -> c.poller(Pollers.fixedRate(10000))) .log() .handle(msg -> { try { System.out.println("msg:" + msg); MimeMessage mimeMsg = (MimeMessage) msg.getPayload(); System.out.println("mimeMsg subject:" + mimeMsg.getSubject() + " \t content:" + mimeMsg.getContent()); } catch (MessagingException | IOException ex) { Logger.getLogger(Job1.class.getName()).log(Level.SEVERE, null, ex); } }) .get(); return ret; }} 参考: