【发布时间】:2020-12-09 03:31:45
【问题描述】:
您好,我正在尝试使用 spring 邮件集成来读取最终用户的邮箱。我使用了以下代码,它工作正常。
@SpringBootApplication
public class ImapTestApplication {
public static void main(String[] args) {
SpringApplication.run(ImapTestApplication.class, args);
ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/gmail-imap-idle-config.xml");
DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
inputChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("===================================");
System.out.println("Message: " + message);
System.out.println("===================================");
}
});
}
还有我的xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:util="http://www.springframework.org/schema/util">
<int:channel id="receiveChannel" />
<!-- replace 'userid and 'password' with the real values -->
<int-mail:imap-idle-channel-adapter id="customAdapter"
store-uri="imaps://mailaddress:password@host:993/inbox"
channel="receiveChannel"
auto-startup="true"
should-delete-messages="false"
should-mark-messages-as-read="false"
java-mail-properties="javaMailProperties"/>
<util:properties id="javaMailProperties">
<prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.imap.socketFactory.fallback">false</prop>
<prop key="mail.store.protocol">imaps</prop>
<prop key="mail.imaps.auth">true</prop>
<prop key="mail.debug">false</prop>
</util:properties>
</beans>
在我的应用程序中,我的数据库中有 100 多个用户邮箱信息。那么我需要如何从我的数据库进行配置。而且在运行时,如果用户更改了密码更改等邮件设置,它也应该执行我的邮件接收器,我尝试使用 Spring Integration Java DSL 来实现 但我不能使用用户邮件数据库中的 imap 设置。
【问题讨论】:
标签: java spring spring-boot spring-integration