For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

Attachment Transformer in Mule | Mail Transfer through SMTP

  Attachment Transformer in Mule | Mail Transfer through SMTP




An attachment transformer is used to set, remove, or copy attachments on the outbound scope of a message.
Each Mule message consists of two parts. The header contains metadata pertaining to the message, such as the message type and the encoding protocol used to format the payload. The payload holds the data that typically gets processed by the Mule application flow, then dispatched to one or more external parties. This payload may also include a sub-section that holds any attachments (such as text, images, or applications) that travel with the message.

When an attachment is received into a flow along with its associated message, it is considered an inbound property, and it remains active (that is, affixed to its parent message) as long as that message remains within the same flow. Note that the attachment does not automatically become part of the processed message that gets sent out of the flow by the outbound connector. For that to happen, you must explicitly make it an outbound property by reattaching it to the message with the attachment transformer. Alternatively, you can designate a different attachment to leave the flow along with the processed message.


The attachment transformer can use expressions that evaluate the content of the current message as well as the current state of the Mule environment in order to make a runtime determination as to which specific attachment leaves the flow with the current message. For example, the Attachment transformer can retrieve a photo that matches some content in the message payload and affix it to the message.

flow of Attachment Transformer :



Attachment configuration :




SMTP connector settings :





go to connector configuration and select Gmail then fill necessary fields mentioned below




Go to advance tab and put key-value mentioned below :







URL : http://localhost:8085/api/attachment
Method : POST

Input : 



Output :

logger output :



One important thing is you might get critical security alert mail from google for sign in by some different device. for this you have to turn on less secure app access by link :


https://myaccount.google.com/lesssecureapps





then go to critical security alert mail sent by google and choose option Yes it was me





Now its all set !!!....Hit the URL and you will get the mail in your inbox.



XML project code :



<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
    <smtp:connector name="SMTP" contentType="text/plain" fromAddress="****@gmail.com" subject="Hello" validateConnections="true" doc:name="SMTP"/>
    <smtp:gmail-connector name="Gmail" contentType="text/plain" fromAddress="****@gmail.com" subject="Hello" validateConnections="false" doc:name="Gmail"/>
    <flow name="test_attachmentFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/attachment" doc:name="HTTP"/>
        <set-attachment attachmentName="doc" value="#[payload]" contentType="text/plain" doc:name="Attachment"/>
        <object-to-string-transformer doc:name="Object to String"/>
        <smtp:outbound-endpoint host="smtp.gmail.com" port="587" user="****@gmail.com" password="*****" connector-ref="Gmail" to="****@gmail.com" from="****@gmail.com" subject="Hello" responseTimeout="10000" mimeType="text/plain" doc:name="SMTP">
            <property key="mail.smtp.starttls.enable" value="true"/>
        </smtp:outbound-endpoint>
       
    </flow>
</mule>






Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER