Announcement Announcement Module
Collapse
No announcement yet.
mail:header-enricher Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mail:header-enricher

    I am trying to use the header enricher of integration's mail support to pull the subject and the from email address and add them to a message header. However, I am not sure how to accomplish this.

    Basically, the incoming email will digested by and mail inbound channel adapter, and put on a channel. What I then wanted to do was to enrich the message as described above, and feed this into a router to handle the processing of information.

    In a separate question, in using the expression language in a header enricher, what is the syntax to use to pass the current message into the method.

    Thanks

  • #2
    What do you want to route based on?

    Comment


    • #3
      mail:header-enricher

      I am trying to be able to route on a result parse in the subject line. Specifically, if the subject contains a reference like (TICKET-100) in the subject line, it is related to a record in our ticket table with the primary key of 100, and is routed down that channel. Otherwise, it goes down a new channel to create a new record.

      I was hoping to enrich the message with the subject to do the parse, as well as the from email address to do checks in our system that it was a registered user of the system, and if they have defined access to the appropriate ticket, etc.

      Ken

      Comment


      • #4
        Ok, first of all mail header enricher is used to send mail not to receive.

        For your use case (routing based on the subject) there are quite a few simple ways. Here is a couple.

        1. Header Enricher -> Header Value Router
        Code:
        <int:header-enricher input-channel="mailReceiveChannel" output-channel="routingChannel">
        		<int:header name="SUBJECT" expression="payload.getSubject()"/>
        </int:header-enricher>
        	
        <int:header-value-router input-channel="mailReceiveChannel" header-name="SUBJECT">
        		<int:mapping channel="channelA" value="TICKET-100"/>
        		<int:mapping channel="channelB" value="TICKET-200"/>
        </int:header-value-router>
        Since the payload of the Message is a MimeMessage you can simply execute payload.getSubject() using SpEL and set it as SUBJECT header. Then use HeaderValueRouter and route based on the value of SUBJECT header.

        2. RecipientListRouter with selector expression

        Code:
        <int:recipient-list-router input-channel="mailReceiveChannel">
        		<int:recipient channel="ticket100-channel" selector-expression="payload.getSubject().endsWith('100')"/>
        		<int:recipient channel="ticket100-channel" selector-expression="payload.getSubject().endsWith('200')"/>
        	</int:recipient-list-router>
        If your selection/routing logic is simple enough to be handled by SpEL, then as you can see a simple selector-expression would eliminate the need for enriching the headers and instead use recipient-list-router with boolean SpEL expression thus still routing to a single channel.

        Comment

        Working...
        X