I've tried all manner of examples to make the properties on the smtp outbound-endpoint dynamic based on the incoming object (e.g. email address). No luck.
In my case, there's a Message object that is put on "queue.passwordChangeEmail". Message/Password/email contains the address I want used in the "to" field.
I've included a minimal set of configuration that does send an email. All that's missing is accessing the Message object to use the email as the "to" field.
Some things I've tried and issues I've encountered:
If I don't include the object-to-string-transformer, then the email is never sent. Depending on where I reference the transformer, I get no email.
I've tried creating a custom transformer that calls muleMessage.setOutboundProperty("to", email), then returns a string as the body of the email. Despite where I've referenced the custom transformer, it never gets called.
I've tried xpath expressions like to="#[string:#[xpath:/Message/Password/email/text()]]" and to="[string:[xpath:/Message/Password/email/text()]]". Still no luck.
<vm:endpoint name="queue.passwordChangeEmail" path="queue.passwordChangeEmail"/>
<flow name="service.passwordChangeEmail">
<description>
Send the password change email
</description>
<vm:inbound-endpoint ref="queue.passwordChangeEmail"/>
<object-to-string-transformer/>
<smtp:outbound-endpoint
host="localhost" port="25"
subject="Password Change"
</flow>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:element name="Message">
<xs:complexType>
<xs:choice>
<xs:element name="Password" type="PasswordType"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="PasswordType">
<xs:attribute name="email" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
public class PasswordChangeEmailTransformer extends AbstractMessageTransformer {
public PasswordChangeEmailTransformer() {
super();
registerSourceType(DataTypeFactory.create(Message.class));
setReturnDataType(DataTypeFactory.TEXT_STRING);
}
@Override
public Object transformMessage(final MuleMessage muleMessage, final String encoding) throws TransformerException {
System.out.println("muleMessage = " + muleMessage);
final com.athieme.dartmouth.admin.Message message = (Message) muleMessage.getPayload();
System.out.println("message = " + message);
final PasswordType password = message.getPassword();
System.out.println("password = " + password);
final String email = password.getEmail();
System.out.println("email = " + email);
muleMessage.setOutboundProperty("to", email);
return "Here's your password change email.";
}
}