Spring XD - outlook的邮件接收器配置

时间:2015-02-27 11:25:09

标签: outlook spring-xd

我正在尝试配置Spring XD的邮件接收器以将消息发送到Outlook帐户。这是我的流定义:

stream create outlookMailSink --definition "http | mail --to='\"email@address.com\"' --host=outlook.office365.com --subject=payload+' world'" --deploy

我正在使用此shell命令进行测试:

http post --data Hello

我收到以下错误消息:

Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:84)

我在Spring XD文档和互联网搜索中对此进行了调查,但我找不到可行的解决方案。有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,涉及创建一个新的邮件接收器模块,这是对Spring XD提供的邮件接收器模块的略微修改。流还必须包括to,from,host,port,username和password选项。

  1. 复制..\spring-xd-<version>\xd\modules\sink\mail文件夹并重命名为secure-mail。
  2. ..\spring-xd-<version>\xd\modules\sink\secure-mail分别将mail.propertiesmail.xml重命名为secure-mail.propertiessecure-mail.xml
  3. 使用以下内容替换secure-mail.xml的内容:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/integration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    
    <channel id="input" />
    
    <int-mail:header-enricher input-channel="input" output-channel="send">
        <int-mail:to expression="${to:null}" />
        <int-mail:from expression="${from:null}" />
        <int-mail:subject expression="${subject:null}" />
        <int-mail:cc expression="${cc:null}" />
        <int-mail:bcc expression="${bcc:null}" />
        <int-mail:reply-to expression="${replyTo:null}" />
        <int-mail:content-type expression="${contentType:null}" />
    </int-mail:header-enricher>
    
    <channel id="send" />
    
    <int-mail:outbound-channel-adapter
        channel="send" host="${host}" port="${port}" username="${username:}"
        password="${password:}" java-mail-properties="javaMailProperties"/>
    
    <util:properties id="javaMailProperties">
        <beans:prop key="mail.smtp.starttls.enable">true</beans:prop>
    </util:properties>
    
    </beans:beans>
    
  4. 按如下方式创建流:

    stream create outlookMailSink --definition "http | secure-mail --to='\"email@address.com\"' --from='\"email@address.com\"' --host=outlook.office365.com --port=587 --username=email@address.com --password=password --subject=payload+' world'" --deploy
    
  5. 使用shell命令测试:http post --data Hello

  6. secure-mail.xml的内容与mail.xml几乎相同,关键是将属性mail.smtp.starttls.enable设置为true,以便通过端口587进行通信的TLS加密。当然,你可以只需直接修改Spring XD的邮件接收器模块并使用它 - 这取决于你。

    我有兴趣听听是否有人有更好的解决方案?例如,是否可以在Spring XD启动时设置mail.smtp.starttls.enable属性,从而允许您使用原始邮件接收器模块?我通过修改xd-singlenode启动脚本尝试了这个 - 该属性已设置,但它不会影响邮件接收器模块。

    <强>参考文献: