简体   繁体   中英

How to read values from a DB and use them with the SMTP connector in Mule 3

I would like to read some email details from the DB, and here's what my connector looks like:

<jdbc:connector name="dbConnector" dataSource-ref="dataSource">
    <jdbc:query key="sqlQuery"
        value="SELECT from, to, subject, body FROM email WHERE status='PENDING'" />
    <jdbc:query key="sqlQuery.ack"
        value="UPDATE email SET status='IN PROGRESS' WHERE id=#[map-payload:id]" />
</jdbc:connector>

I would then like to use those details to send a bunch of mails. I expect that the inbound-endpoint will be the JDBC Connector and the outbound-endpoint will be SMTP Connector, but I don't know how to store and use data I read from that table. Is there a way to do this without resorting to Java code?

Using transformers should be enough to achieve your goal: the inbound JDBC endpoint will give you a Map payload. From this payload you will extract the properties required by the outbound SMTP endpoint and the body of the message:

<!-- Set SMTP endpoint properties -->
<message-properties-transformer>
  <add-message-property key="subject" value="#[map-payload:subject]"/>
  ...
</message-properties-transformer>
<!-- Set the message Body as new payload -->
<expression-transformer>
  <return-argument evaluator="map-payload" expression="body"/>
</expression-transformer>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM