gpt4 book ai didi

email - spring 接收没有 xml 的电子邮件(仅使用注释)

转载 作者:行者123 更新时间:2023-12-01 12:31:56 25 4
gpt4 key购买 nike

我需要定期检查大约 30 个邮箱,并且只想使用注释来完成此操作。我知道如何处理 XML 文件,它看起来像这样:

<mail:inbound-channel-adapter id="ImapAdapter"
store-uri="imaps://${login}:${pass}@${host}:993/inbox"
channel="testReceiveEmailChannel"
should-delete-messages="false"
should-mark-messages-as-read="true"
auto-startup="true"
java-mail-properties="javaMailProperties">
<int:poller fixed-delay="200"
time-unit="SECONDS"
task-executor="asyncTaskExecutor"/>
</mail:inbound-channel-adapter>

<int:channel id="testReceiveEmailChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>

<int:service-activator input-channel="testReceiveEmailChannel"
ref="testMailReceiverService"
method="receive"/>

<bean id="testMailReceiverService" class="com.myproject.email.EmailReceiverService">
<property name="mailBox" value="${login}"/>
</bean>


<int:logging-channel-adapter id="logger" level="DEBUG"/>

我知道 Spring 4+ 有 @InboundChannelAdapter 但我不知道如何使用它。其实我是 Spring 的新人,所以非常感谢任何帮助!

最佳答案

您正在研究正确的方法 - @InboundChannelAdapter。如果你看一下 Documentation正确的,你会看到这样的东西:

@Bean
@InboundChannelAdapter(value = "testReceiveEmailChannel", poller = @Poller(fixedDelay = "200000", taskExecutor = "asyncTaskExecutor"))
public MessageSource<javax.mail.Message> mailMessageSource(MailReceiver mailReceiver) {
MailReceivingMessageSource mailReceivingMessageSource = new MailReceivingMessageSource(mailReceiver);
// other setters here
return mailReceivingMessageSource;
}

MailReceiver 是这样的:

@Bean
public MailReceiver imapMailReceiver(@Value("imaps://${login}:${pass}@${host}:993/inbox") storeUrl) {
ImapMailReceiver imapMailReceiver = new ImapMailReceiver(storeUrl);
// other setters here
return imapMailReceiver;
}

还有用于 MessageChannel 的其他 @Bean 和用于您的 EmailReceiverService@ServiceActivator

考虑将 Spring Integration Java DSL 作为 Java 配置工具.

关于email - spring 接收没有 xml 的电子邮件(仅使用注释),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32401643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com