Stuart
Stuart

Reputation: 3356

Spring XD - mail sink configuration for outlook

I'm trying to configure Spring XD's mail sink to send messages to an outlook account. This is my stream definition:

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

I'm testing using this shell command:

http post --data Hello

I am getting the following error message:

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)

I have investigated this in the Spring XD documentation and internet searches but I haven't found a solution that works. Can anyone help me with this please?

Upvotes: 0

Views: 578

Answers (1)

Stuart
Stuart

Reputation: 3356

I found a solution which involves creating a new mail sink module which is a slight modification of spring XD's supplied mail sink module. The stream must also include to, from, host, port, username and password options.

  1. Copy the ..\spring-xd-<version>\xd\modules\sink\mail folder and rename to secure-mail.
  2. In ..\spring-xd-<version>\xd\modules\sink\secure-mail rename both mail.properties and mail.xml to secure-mail.properties and secure-mail.xml respectively.
  3. Replace the contents of secure-mail.xml with the following:

    <?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. Create the stream as follows:

    stream create outlookMailSink --definition "http | secure-mail --to='\"[email protected]\"' --from='\"[email protected]\"' --host=outlook.office365.com --port=587 [email protected] --password=password --subject=payload+' world'" --deploy
    
  5. Test using shell command: http post --data Hello

The contents of secure-mail.xml is almost identical to mail.xml, the key is to set the property mail.smtp.starttls.enable to be true in order to enable TLS encryption for communication over port 587. OF course you could just modify Spring XD's mail sink module directly and use this - it's up to you.

I'd be interested to hear if anyone has a better solution to this? For example, is it possible to set the mail.smtp.starttls.enable property on start-up of Spring XD thereby allowing you to use the original mail sink module? I tried this by modifying the xd-singlenode startup script - the property was set but it didn't affect the mail sink module.

References:

Upvotes: 0

Related Questions