我是的新手,我希望阅读文件的内容,并将其用作电子邮件的正文/文本。这是使用最新版本的Spring (不确定确切的ver )。不。)。请注意,我将只根据Spring库和类本身中可用的内容使用Spring配置文件
到目前为止,我尝试过的是:
<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帐户。如有任何指示,将不胜感激。
发布于 2019-11-27 22:18:20
到目前为止,我看到的是outputContent作为DirectChannel,而这个用户有两个订户:<int-file:outbound-channel-adapter id="filesOut">和<int:header-enricher。
默认情况下,DirectChannel为其订阅者应用循环消息分发。因此,第一条消息转到第一订户,第二到第二,第三到第一次。
请考虑不要使用该int-file:outbound-channel-adapter:您刚刚通过<int-file:inbound-channel-adapter读取了该文件。而且我看到你看完后就把它删掉了。那么,如果您的目标是发送电子邮件,那么将其写回其他目录又有什么意义呢?
https://stackoverflow.com/questions/59079030
复制相似问题