Friday, October 18, 2019

How to send error email in wso2_ESB-part1

<?xml version="1.0" encoding="UTF-8"?>
<template name="Error_Email_Notification" xmlns="http://ws.apache.org/ns/synapse">
    <sequence>
        <clone continueParent="true">
            <target>
                <sequence>
                    <property expression="get-property($url:key)" name="To" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
                    <property expression="get-property('SERVER_HOST')" name="ServerHost" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
                    <property expression="fn:concat('[', $ctx:ServerHost ,']')" name="environment" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
                    <property expression="fn:concat($ctx:environment, ' An Error Occurred Service : ',$ctx:proxy.name)" name="Subject" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
                    <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
                    <property name="transport.mail.Format" scope="axis2" type="STRING" value="Attachment"/>
                    <property name="AttachmentFile" scope="axis2" type="STRING" value="ErrorMessage.xml"/>
                    <property expression="$ctx:messageBody" name="transport.mail.bodyWhenAttached" scope="axis2" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
                    <header action="remove" name="To" scope="default"/>
                    <property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
                    <property name="RESPONSE" scope="default" type="STRING" value="true"/>
                    <property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
                    <property name="messageType" scope="axis2" type="STRING" value="text/html"/>
                    <property name="FORCE_ERROR_ON_SOAP_FAULT" scope="default" type="STRING" value="true"/>
                    <payloadFactory media-type="xml">
                        <format>
                            <Fault>
                                <ERROR_CODE>$1</ERROR_CODE>
                                <ERROR_MESSAGE>$2</ERROR_MESSAGE>
                                <ERROR_DETAIL>$3</ERROR_DETAIL>
                            </Fault>
                        </format>
                        <args>
                            <arg evaluator="xml" expression="get-property('ERROR_CODE')" xmlns:ns="http://org.apache.synapse/xsd"/>
                            <arg evaluator="xml" expression="get-property('ERROR_MESSAGE')" xmlns:ns="http://org.apache.synapse/xsd"/>
                            <arg evaluator="xml" expression="get-property('ERROR_DETAIL')" xmlns:ns="http://org.apache.synapse/xsd"/>
                        </args>
                    </payloadFactory>
                    <send>
                        <endpoint>
                            <address uri="mailto:"/>
                        </endpoint>
                    </send>
                </sequence>
            </target>
        </clone>
    </sequence>
</template>

Note:TO_email-ids taking in local_entries. 

No comments:

Post a Comment