我是Spring Integration的新手,我希望阅读文件的内容,并将其用作电子邮件的正文。这使用的是Spring的最新版本(不确定确切的版本号)。请注意,我将仅基于Spring库和类本身中可用的内容使用Spring XML配置文件。
这是我到目前为止尝试过的:
<int-file:inbound-channel-adapter id="filesReader"
directory="file:/C:/data/inputDirectory"
filename-pattern="*.txt"
channel="filesIn"
prevent-duplicates="true">
<int:poller id="poller" fixed-delay="1000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>
<!-- convert contents to string -->
<file:file-to-string-transformer input-channel="filesIn" output-channel="outputContent" delete-files="true"/>
<!-- output content to a file so the payload can be read by the logger -->
<int-file:outbound-channel-adapter id="filesOut" directory="file:/C:/data/outputDirectory" channel="outputContent"/>
<int:channel id="outputContent">
<int:interceptors>
<int:wire-tap channel="LoggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="LoggingChannel" />
<int:service-activator input-channel="LoggingChannel" expression="@LOG.trace('LOG Payload is: {} ', payload)" />
<bean id="LOG" class="SafeLoggerFactory" factory-method="getLogger">
<constructor-arg value="integrationEmailLogger"/>
</bean>
<int:channel id="mailMessageChannel"/>
<int:header-enricher input-channel="outputContent" output-channel="mailMessageChannel">
<int:header name="mail_from" value="${email}"/>
<int:header name="mail_subject" value="Subject goes here"/>
<int:header name="mail_to" value="${email}"/>
</int:header-enricher>
<mail:outbound-channel-adapter channel="mailMessageChannel" mail-sender="mailSender">
<mail:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="payload.length"/>
<property name="onFailureExpression" value="payload.length"/>
</bean>
</mail:request-handler-advice-chain>
</mail:outbound-channel-adapter>
<!--<int:channel id="outboundMailChannel" />
<int:transformer method="transformToMimeMessage" input-channel="outputContent" output-channel="outboundMailChannel"/>
<mail:outbound-channel-adapter mail-sender="mailSender" channel="outboundMailChannel">
<mail:request-handler-advice-chain>
<int:retry-advice max-attempts="5">
<int:fixed-back-off interval="10000"/>
</int:retry-advice>
</mail:request-handler-advice-chain>
</mail:outbound-channel-adapter>-->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="587"/>
<property name="protocol" value="smtp"/>
<property name="username" value="${email}"/>
<property name="password" value="${password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.starttls.required">true</prop>
</props>
</property>
</bean>
我可以获取文件的内容以打印到日志文件,但是似乎没有从我的gmail帐户发送电子邮件。任何指针,将不胜感激
我是Spring Integration的新手,我希望阅读文件的内容,并将其用作电子邮件的正文。这使用的是Spring的最新版本(不确定确切的版本号)。请注意,我'...
到目前为止,我看到您有一个outputContent
作为DirectChannel
,并且这个有两个订阅者:[C0