Is it possible with WSO2ESB to send E-Mail Using Header - wso2

i wish to send a e-mail to my client using Header mediator .
Is it possible with that or not
My proxy like this
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Mail"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log/>
<property name="workpartybranchid"
expression="//workpartybranchid/text()"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:SelectMail_Op xmlns:p="http://ws.wso2.org/dataservice">
<p:workpartybranchid>$1</p:workpartybranchid>
</p:SelectMail_Op>
</format>
<args>
<arg expression="get-property('workpartybranchid')"/>
</args>
</payloadFactory>
<send receive="Mailseq">
<endpoint>
<address uri="http://192.168.1.4:9773/services/muser_DataService/"
format="soap11"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy
and corresponding sequence is
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Mailseq" onError="fault">
<property name="CONTENT_TYPE"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
</log>
<header name="To" expression="fn:concat('mailto:', get-property('primarymail'))"/>
<send/>
<log>
<property name="mail" value="ts working"/></log>
</sequence>
can we send a email like this i have got reference from this
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
i am posted my requirement in another way also please refer this
Can we send Multiple Mail in wso2esb in same sequence or dynamically set a mail

Just follow the step in below URL ( but rather than header part, use endpoint for this as below.. this worked for me)
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
Add Send for mail as below...( no need header mediator)
<send> <endpoint>
<address uri="mailto:yourmailaddr#gmail.com" />
</endpoint>
</send>

Related

WSO2 Ei 6.1 email received as attachment

I have a service which send the email from WSo2 server. But i am getting the message content as attachment and not in body of the email.
You can define the message content for the email body using payload factory mediator as below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="mailtest"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<payloadFactory media-type="xml">
<format>
<test xmlns="">$1</test>
</format>
<args>
<arg xmlns:ax21="http://services.samples/xsd"
xmlns:ns="http://services.samples"
evaluator="xml"
expression="//ns:getQuoteResponse/ns:return/ax21:name"/>
</args>
</payloadFactory>
<property name="Subject" scope="transport" value="Sample Mail"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/plain"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="mailto:yourmail#gmail.com"/>
</endpoint>
</send>
</outSequence>
</target>
<description/>
</proxy>
If you want to define a message body with the email attachment, use "transport.mail.bodyWhenAttached" property.

How to send to multiple endpoints in wso2esb

I am using wso2esb-4.8.1,
I wish to log the transaction details after response back to client.
For that I have written Proxy as well as sequence but wso2esb-4.8.1 is not supporting that with send mediator ,because I want t use load balance for every endpoint where as same logic is working in CallOUt mediator with URL option not with address endpoint .
proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_Proxy" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="ProxyInRequest"
expression="/soapenv:Envelope"/>
</log>
<xquery key="ProxyRequestTransformation">
<variable xmlns:ns="http://org.apache.synapse/xsd" name="Operation" expression="//Operation/text()" type="STRING"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceNameSpace" expression="//ServiceNameSpace/text()" type="STRING"/>
<variable name="Payload" type="DOCUMENT_ELEMENT"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceName" expression="//Service/text()" type="STRING"/>
</xquery>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
<send/>
<sequence key="AuditSeq"/>
</outSequence>
</target>
<publishWSDL key="EaiEnvelope"/>
</proxy>
In above proxy i have used default send mediator after that trying to do audit in same flow ,My client is getting response back but details are not auditing even not getting any error.
My sequence
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditSeq"> <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_CODE" expression="get-property('ResultCode')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_MESSAGE" expression="get-property('ResultMessage')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="REFERENCE_ID" expression="get-property('ReferenceID')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="FAULT_DETAILS" expression="concat(get-property('ERROR_CODE'),get-property('ERROR_MESSAGE'))" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<open:processRequest xmlns:open="http://www.openuri.org/">
<aud:Auditor xmlns:aud="http://jhm.kkk.fff/Auditor">
<aud:Request>
<aud:Operation_Name>processRequest</aud:Operation_Name>
<aud:Auditor_InputData>
<aud:Result_Code>$1</aud:Result_Code>
<aud:Result_Message>$2</aud:Result_Message>
<aud:Reference_Id>$3</aud:Reference_Id>
</aud:Auditor_InputData>
</aud:Request>
</aud:Auditor>
</open:processRequest>
</format>
<args>
<arg evaluator="xml" expression="get-property('RESULT_CODE')"/>
<arg evaluator="xml" expression="get-property('RESULT_MESSAGE')"/>
<arg evaluator="xml" expression="get-property('REFERENCE_ID')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="http://www.openuri.org/processRequest"/>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
</endpoint>
</send>
<log>
<property name="aftersend" value="message going out or not"/>
</log>
</sequence>
With above send mediator is not working .But after send my log is printing.
If i replace send mediator with CallOut URL option its working fine.
<callout serviceURL="http:///localhost:8081/middleware/services/AuditService">
<source type="envelope"/>
<target key="IsThisResponse"/>
</callout>
In above we are not able to use loadbalancing.For that I trying for send mediator.
Is any way to do this.
I thouhgt wso2esb-4.8.1 is become stable but again its having drawbacks.
Thanks in advance.
Please try by changing the send mediator in your proxy as mentioned here it may help you
<send receive="AuditSeq">
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>

Can we Set a Send mediator with Xpath expression

i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..

How to Know the URL of Client In wso2 esb for Filter

i am doing filter based on the URL so i wish to know the FROM which service i am getting request .Means i wish to know the URL of Client
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Emp" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<payloadFactory>
<format>
<send xmlns="">
<username>$1</username>
<password>$2</password>
</send>
</format>
<args>
<arg expression="get-property('username')"/>
<arg expression="get-property('password')"/>
</args>
</payloadFactory>
<send receive="Emp_Seq">
<endpoint>
<address uri="http://192.168.1.65:8282/services/Login"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
URL of above Proxy is http://192.168.1.65:8282/services/Emp
my second proxy is which will do some logic based on first proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Login" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="client_ip_address" expression="get-property('axis2','REMOTE_ADDR')" scope="default" type="STRING"/>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<property name="From" expression="get-property('From')"/>
<property name="Address" expression="get-property('To')"/>
<filter xmlns:ns="http://org.apache.synapse/xsd" xpath="get-property('From')='/services/Emp'">
<then>
<payloadFactory>
<format>
<ResponseJSON xmlns="">
<Status>404</Status>
<Exception>Not Found</Exception>
<Total>0</Total>
</ResponseJSON>
</format>
</payloadFactory>
<send/>
</then>
<else>
<payloadFactory>
<format>
<p:login xmlns:p="http://authentication.services.core.carbon.wso2.org">
<p:username>$1</p:username>
<p:password>$2</p:password>
<p:remoteAddress>$3</p:remoteAddress>
</p:login>
</format>
<args>
<arg expression="//username/text()"/>
<arg expression="//password/text()"/>
<arg expression="get-property('client_ip_address')"/>
</args>
</payloadFactory>
<header name="Action" value="urn:login"/>
<log level="full"/>
<send receive="Login_Seq">
<endpoint>
<address uri="https://192.168.1.65:9443/services/AuthenticationAdmin" format="soap11"/>
</endpoint>
</send>
</filter>
</inSequence>
<outSequence>
<log level="full"/>
</outSequence>
</target>
<description></description>
</proxy>
The issue is get-property('To') is giving Address=/services/Login where as get-property('From') is giving senderAddress=null
How can i manage this i trie d with lot of propertys even though its not working
like
<property name="senderAddress" expression="get-property('transport', 'From')"/>
<property name="Sender Address" expression="$url:From"/>
<header name="From" expression="get-property( 'From')"/>
<property name="PRESERVE_WS_ADDRESSING" value="true"/>
<property xmlns:wsa="http://www.w3.org/2005/08/addressing" name="$header" expression="$header/wsa:From"/>
This propertys also not working we don't have any option in wso2 esb If you know this please edit my proxy roughly ..its simple depanding logic but it is not working in WSO2
thanks in advance
You should be able to get the client's address with the REMOTE_HOST or REMOTE_ADDR properties. Please refer http://wso2.org/project/esb/java/4.0.3/docs/properties_guide.html#http

Can we append the data in single text file using WSO2ESB?

I am getting error message from mobile app or somewhere any of front end.
I need keep that message in one single text file. That file could be stored in my local system.
How can I do this using WSO2ESB?
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AppendFile" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence onError="fault">
<property name="error_TYPE" expression="//error/text()" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory>
<format>
<error></error>
</format>
<args>
<arg expression="get-property('error')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="//home/desktop/append.txt"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="CONTENT_TYPE" value="application/json" scope="axis2"/>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
But its giving transport error.
How can we do this? Please suggest.
You can use VFS transport. Please refer.
http://achala11.blogspot.com/2012/08/vfs-transport-wso2-esb-using-file.html
http://docs.wso2.org/wiki/display/ESB460/VFS+Transport
http://docs.wso2.org/wiki/pages/viewpage.action?pageId=16846489
what is the error you got?
Anyway the endpoint you gave looks wrong. It should start with the transport protocol as vfs://
eg: vfs:file:///home/desktop/append.txt