Java 带数据库的spring启动邮件接收器
您好,我正在尝试使用SpringMail集成读取最终用户邮箱。我使用了下面的代码,它工作得很好Java 带数据库的spring启动邮件接收器,java,spring,spring-boot,spring-integration,Java,Spring,Spring Boot,Spring Integration,您好,我正在尝试使用SpringMail集成读取最终用户邮箱。我使用了下面的代码,它工作得很好 @SpringBootApplication public class ImapTestApplication { public static void main(String[] args) { SpringApplication.run(ImapTestApplication.class, args); ApplicationContext
@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("===================================");
}
});
}
@springboot应用程序
公共类ImapTestApplication{
公共静态void main(字符串[]args){
run(ImapTestApplication.class,args);
ApplicationContext ac=new ClassPathXmlApplicationContext(“/META-INF/gmail imap idle config.xml”);
DirectChannel inputChannel=ac.getBean(“receiveChannel”,DirectChannel.class);
订阅(新的MessageHandler(){
public void handleMessage(消息消息消息)引发MessaginException{
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>
javax.net.ssl.SSLSocketFactory
假的
imaps
真的
假的
在我的应用程序中,我的数据库中有100多个用户的邮箱信息。因此,我需要如何从我的数据库进行配置。而且在运行时,如果用户更改邮件设置(如密码更改),也应该执行我的邮件收件器,我尝试使用Spring Integration Java DSL实现
但是我不能使用用户邮件数据库中的imap设置。使用XML配置确实没有简单的方法 这里有一些例子: 为每个客户创建一个新的应用程序上下文 有了JavaDSL及其动态流特性,在运行时从任意代码中制作一些
IntegrationFlow
就容易多了
您还可以将它们映射到那些用户,以便在属性更改时能够销毁和创建新的用户
请参阅文档中的更多内容:谢谢您的回复。是否有任何示例代码或详细的文档JavaDsL与IMAP邮件服务?请参阅文档中的此处。此处作为测试套件:另请参阅。它采用动态ftp方法,用于使用子上下文和Java配置的邮件适配器,但我同意Artem的观点,动态DSL现在是最好的解决方案。