需要<int-mail:outbound-channel-adapter> </int-mail:outbound-channel-adapter>的任何工作示例

时间:2014-07-15 17:45:45

标签: spring-integration

任何人都可以为?

提供工作示例(配置)

我检查了#34; Spring Integration Reference Manual&#34;和github所有si样本都已提供,但我找不到任何东西。

2 个答案:

答案 0 :(得分:4)

这样的事情:

<int:chain input-channel="inputChannel">
    <int-mail:header-enricher>
        <int-mail:to value="mailto"/>
        <int-mail:from value="mailfrom"/>
        <int-mail:subject value="With Content Type"/>
        <int-mail:content-type value="text/html"/>
    </int-mail:header-enricher>

    <int-mail:outbound-channel-adapter host="smtp.gmail.com"
                                       port="587"
                                       username="user"
                                       password="password"
                                       java-mail-properties="javaMailProperties"/>
</int:chain>


<util:properties id="javaMailProperties">
    <prop key="mail.debug">true</prop>
    <prop key="mail.smtps.auth">true</prop>
    <prop key="mail.smtp.starttls.enable">true</prop>
</util:properties>

<强>更新

没错:整个payload都会转换为电子邮件。当然,在发送之前transform payload到适当的对象是典型的任务。

MailSendingMessageHandler的{​​{1}}这些类型:

payload

答案 1 :(得分:0)

这是从先前解决方案中提取的另一个示例,其中为文件读取目录,每个文件转换为bytes [],然后发送到邮件。

    <bean id="placeholderConfig"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="locations">
        <list>
            <value>classpath:integration.properties</value>
            <!-- override property files -->
            <value>file:integration.properties</value>
        </list>
    </property>
</bean>

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="${integration.mail.host}" />
</bean>

<file:inbound-channel-adapter id="fileWorkingChannel" 
                directory="file:${integration.file.working.directory}" 
                prevent-duplicates="${integration.file.incoming.prevent.duplicate}" 
                filename-pattern="*.${integration.file.type}">
    <integration:poller fixed-rate="${integration.file.working.poll.rate}"/>
</file:inbound-channel-adapter> 


<file:file-to-bytes-transformer 
    input-channel="fileWorkingChannel"
    output-channel="mailTransportChannel"
    delete-files="true"/>

<integration:channel id="mailTransportChannel"/>

<integration:header-enricher input-channel="mailTransportChannel" output-channel="mailMessageChannel">
    <integration:header name="mail_from" value="${integration.mail.from}"/>
    <integration:header name="mail_subject" expression="'filepath:${integration.mail.file.path}' + '|' + 'filename:' + headers.file_name"/>
    <integration:header name="mail_to" value="${integration.mail.to}"/>
    <integration:header name="mail_attachmentFilename" expression="headers.file_name"/>
</integration:header-enricher>  

<integration:channel id="mailMessageChannel"/>

<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="successChannel" ref="afterSuccessChannel"/>
            <property name="onFailureExpression" value="payload.length"/>
            <property name="failureChannel" ref="afterFailChannel" />
        </bean>
        <bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
            <property name="retryTemplate" ref="retryTemplate"/>
        </bean>
    </mail:request-handler-advice-chain>
</mail:outbound-channel-adapter>