Mule - Personalize Body SMTP Component - string

I have a mule flow that performs the following actions:
HTTP => JSON to XML => XSLT => Logger => SMTP
I want to personalize the body to the Email with the message.payload and my personal text for example:
It has received an XML message with the following information:
#[message.payloadAs(java.lang.String)]
The message.payload is the XML transformed with the XSLT component and the email will be received as follows:
It has received an XML message with the following information:
author:Gambardella, Matthew
What I need to personalize the message with my text?
Should I use a payload component or a property?

the SMTP connector it will use the payload as the body of the mail, so just set in the payload what you want to be sent for example:
<set-payload value="It has received an XML message with the following information: #[message.payloadAs(java.lang.String)]" doc:name="Set Payload"/>
Now if you want to send this email has HTML mail so that in your payload you can add html tag and even styles you can do that by adding to the SMTP a global connector and setting on the global connector the contentType, note that setting the mimeTypedirectly on the SMTP endpoint only will not have effect:
<smtp:connector name="SMTP_exception_mailer" contentType="text/html" validateConnections="true" doc:name="SMTP"/>
<smtp:outbound-endpoint host="host" port="25" connector-ref="SMTP_exception_mailer" to="you#me.com" from="system#mule" mimeType="text/html" doc:name="SMTP"/>
BONUS TIP FOR COMPLEX HTML MAIL
If you want to send complex html mail it's clear that using the set-payload component it will be quite complicated, a good alternative is to use the parse template component, this will allow you to write your html in an external file using also MEL expressions in it.

Related

How to avoid loading email's content using spring integration mail

I am using spring integration mail (5.3.1 release)
I have a flow:
IntegrationFlows
.from(Mail
.imapIdleAdapter(imapAdapter)
)
.filter()
.filter()
...
.filter()
.handle(service1)
.get();
I want an email content to be loaded in service1.
I don't want to load email's content until it passes all filters.
My filters need to know only email headers.
I tried to use DefaultMailHeaderMapper but email's content is loaded anyway. I can see it in logs using "mail.debug"=true.
I was debugging and according to source of AbstractMailReceiver#receive, MimeMessage's content will be always loaded because e.g new IntegrationMimeMessage() uses MimeMessage(MimeMessage message) constructor that loads a content.
Is there any way to configure mail adapter to not load an email's content?
Thank you!
See docs: https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#mail-inbound. Especially this part:
tarting with version 5.2, the autoCloseFolder option is provided on the mail receiver. Setting it to false doesn’t close the folder automatically after a fetch, but instead an IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE header (see MessageHeaderAccessor API for more information) is populated into every message to producer from the channel adapter.
And then take a look into the next section: https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#mail-mapping
So, to avoid eager content loading you should abandon the header mapper and don't close the folder automatically. This way the whole MimeMessage is sent as a payload. You probably won't be able to perform your filtering logic against headers because the content of the message is not fetched therefore we don't know what headers are there in MimeMessage. However you can try to get access to them from your filters, but already against the payload - not headers.

IBM Integration Bus web service client request

I have to send a scheduled request to a SOAP web service with attachment (a zip) and metadata in the request . The data and file are prepared in a .NET compute node and a SOAP request node is made by a WSDL file. Unfortunately I do not know how I could pass the metadata and file to the SOAP request node from .NET compute node. The metadata is in the tag of the envelope, the uuid of the attachment is in the tag of the body. And the file goes into the attachment part.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:tag="http://....">
<soap:Header>
<tag:metadata>
<tag:filename>filename</tag:filename>
<tag:date>2018-06-01</tag:date>
</tag:metadata>
</soap:Header>
<soap:Body>
<tag:file>
<tag:content>cid:4444444</tag:content>
</tag:file>
</soap:Body>
</soap:Envelope>
Could someone help me, please?
SOAP nodes support MTOM attachment handling, so IIB will take care of that automatically. The requirements are outlined in the IIB knowledge center:
An MTOM output message is written if all of the following criteria are met:
The Allow MTOM property is selected on the WS Extensions tab.
Validation is enabled. The Validate property on the SOAPRequest and SOAPAsyncRequest nodes controls validation of the anticipated response message and not validation of the outgoing request. MTOM output is therefore suppressed unless you set Validate to Content and value on a preceding input node or transformation node.
No child elements exist below SOAP.Attachment in the logical tree. If child elements are present, SOAP with Attachments (SwA) is used.
Elements exist in the output message that are identified as base64Binary in the associated XML Schema and whose length does not fall below a default threshold size of 1000 bytes.
https://www.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ac56630_.htm
So you just put the binary data in your content element (provided that it has the correct type in the schema) as BLOB and configure the flow as above.

Jain-Sip dialog message body

I have an app using JAIN-SIP. The application will send SIP NOTIFY messages with event type dialog and content-type application/dialog-info+xml.
Is there an API for building the (xml) message body. The javax.sip.message.MessageFactory takes a java.lang.Object for the message body, since the type can vary depending on the request. But are there any libraries to facilitate constructing the format of the body?

Logic App Send Message error with JSON

I'm using Logic App to send a message to a service bus on Azure. The logic app starts with a HTTP Request for the trigger which contains a JSON payload in the body. The 'Body' of the request is set as the Content of the Send Message action. Since the payload is JSON when posting I set the Content-Type to application/json. This generates an error on the Send Message action;
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'Send_message.' inputs at line '1' and column '1221': 'The template language function 'encodeBase64' expects its parameter to be a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#encodeBase64 for usage details.'."}
So tried changing the Content-Type to text/plain and it works? Is this a bug or should convert the JSON to a text value somehow before using it in the Send Message action?
Sending a message to service bus requires the message content to be base64 encoded. Since your content is a JSON, you would need to stringify it explicitly prior to encoding, i.e. use #encodeBase64(string(jsonContent))
Changing the content type to text/plain has the same effect, since in that case the content is treated as a string to begin with.

sending html content in email body(emailBlurb) docusign api

I am trying to send html content in my emailBlurb for sending email for document signature by using the following code portion :
DocumentSignatureRequest documentSignRequest = new documentSignatureRequest();
String blurb = "Testing html email content : <b>Bold content</b>";
documentSignRequest.setEmailBlurb(blurb);
But the emails I receive from this contain the whole string, instead of using the with the <b> instead of bold text. So, I looked at the docs provided by docusign and it indicated for looking at the 'email resource file' in the docusign account. In the file i found the portion :
<td class="MainStyle" colspan="2">
<p>[[EmailBlurb]]</p>
<p>[[RecipientNote]]</p>
</td>
I am guessing the 'emailBlurb' I am setting is being used simply as a string and thus the html tags are just being displayed as is.
So my question, what are my options with finding a way around this. I know an option is to edit the resource file, but are there any other better options. For instance, any settings or tags in the resource file around the [[EmailBlurb]] or if it can be done from my code? Please help.
It's possible to insert raw html into the notification emails however this is not a self-service option. You need to reach out to your DocuSign Account Manager or their Support to have the option enabled in your account.

Resources