SlideShare a Scribd company logo
1 of 17
Send email attachment using
SMTP in Mule ESB
What is Mule ESB ?
 Mule ESB is a lightweight Java-based
enterprise service bus (ESB) and
integration platform that allows
developers to connect applications
together quickly and easily, enabling
them to exchange data. Mule ESB
enables easy integration of existing
systems, regardless of the different
technologies that the applications use,
including JMS, Web Services, JDBC,
HTTP, and more.
 This example shows how we can send email
attachment using SMTP connector to self or
another email. We simply put a file in a source
directory and Mule will read the file from the
source directory. Using Mule ESB it’s very easy
to read the file from a location. If we had to read
the file using manual coding then we had to write
many lines of code. But using Mule ESB we just
simply put a file in a directory and let the Mule
know the file path and Mule does the rest of the
thing. You can put any kind of file to the source
for reading. The file that we put into a source
directory will be an attachment to the intended
recipient’s mail address. So finally when we will
see the file as an attachment in the mailbox.
What is Attachment
transformer ?
 Attachment transformer lets us attach
a file or document which will be sent to
the email address.
What is SMTP connector ?
 The SMTP endpoint allows Mule
messages to be sent as email or email
attachments with the Simple Mail
Transfer Protocol (SMTP) using Java
mail API.
Prerequisites
 Mule Studio 3.5.1
JDK 1.6
Maven 3
Mule Runtime 3.5.0 CE
Knowledge of XML
 Open Mule Studio and create a mule project.
Go to File->New->Mule Project. Now enter
the Project Name, selectRuntime – Mule
Server, check the check box for Use Maven.
Now enter the following information
 Group Id: your Mail(ex. gmail.com)
Artifact Id: project name – file-
attachment(automatically populated when
project name is getting typed)
V
 Click Next and verify project Location and
JRE/JDK are set correctly. Click
Finishersion: Mule studio generates default
 Now drag and drop the elements from right
side of the Mule studio as shown below in
the picture.
Browse and select the path from where a file will be read for an attachment.
Logger component properties
 File to String transformer properties
 File-to-Strong transformer just transforms
the file object to human readable string
format. We will not set any property for this
element
Attachment transformer properties
 Using attachment transformer we can set
payload from previous flow as an
attachment. We have to select Content
Type, operation as Set Attachment, Name,
Value
 SMTP connector properties
For SMTP connector we have to input email host, user name, password, port
under Basic Settings and To Address, From Address, Subject under Email
Information.
 The whole XML file of entire flow
 <?xml version="1.0" encoding="UTF-8"?>

 <mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp"
 xmlns:file="http://www.mulesoft.org/schema/mule/file" 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" version="CE-3.5.0"
 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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
 http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
 <flow name="file-attachmentFlow1" doc:name="file-attachmentFlow1">
 <file:inbound-endpoint path="D:AnypointWorkspacesource"
 responseTimeout="10000" doc:name="File" />
 <logger message="#[payload]" level="INFO" doc:name="Logger" />
 <file:file-to-string-transformer
 doc:name="File to String" />
 <logger message="#[payload]" level="INFO" doc:name="Logger" />
 <set-attachment attachmentName="attachment" value="#[payload]"
 contentType="text/plain" doc:name="Attachment" />
 <logger message="#[payload]" level="INFO" doc:name="Logger" />
 <smtp:outbound-endpoint host="mail.domain.com"
 user="emailAddress@domain.com" password="password" to="emailAddress@domain.com"
 from="emailAddress@domain.com" subject="Test Email" responseTimeout="10000"
 doc:name="SMTP" />
 <logger message="#[payload]" level="INFO" doc:name="Logger" />
 </flow>
 </mule>
 Now create a text file called file-
attachment.txt and put it under selected path,
i.e., as per the above XML the file path
is D:AnypointWorkspacesource.
 Do right-click on file-attachment.xml and
click on Run As -> Mule Application with
Maven. Once the application up and running
you will get the console output and email
attachment in your mailbox where you have
sent the email.
 Output in console
 INFO 2015-03-05 09:25:46,372 [[file-
attachment].connector.file.mule.default.receiver.01]
org.mule.transport.file.FileMessageReceiver: Lock obtained on file:
D:AnypointWorkspacesourcefile-attachment.txt
 INFO 2015-03-05 09:25:46,404 [[file-attachment].file-
attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor:
org.mule.transport.file.ReceiverFileInputStream@6a150e
 INFO 2015-03-05 09:25:46,406 [[file-attachment].file-
attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor:
This is a file content
 INFO 2015-03-05 09:25:46,407 [[file-attachment].file-
attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor:
This is a file content
 INFO 2015-03-05 09:25:46,419 [[file-attachment].file-
attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor:
This is a file content
 INFO 2015-03-05 09:25:46,422 [[file-
attachment].connector.smtp.mule.default.dispatcher.01]
org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default
outbound transformer:
org.mule.transport.email.transformers.ObjectToMimeMessage
 INFO 2015-03-05 09:25:46,428 [[file-
attachment].connector.smtp.mule.default.dispatcher.01]
org.mule.lifecycle.AbstractLifecycleManager: Initialising:
'connector.smtp.mule.default.dispatcher.1213248'. Object is:
SmtpMessageDispatcher
 Click on the attachment. You will see the
below output in the browser.

More Related Content

What's hot

Mule integration
Mule integrationMule integration
Mule integrationSon Nguyen
 
Introduction To Mule
Introduction To MuleIntroduction To Mule
Introduction To MuleRoy Prins
 
Connectors in mule
Connectors in muleConnectors in mule
Connectors in muleSindhu VL
 
Mule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce InterfaceMule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce Interfacekrishananth
 
Mule agent notifications
Mule agent notificationsMule agent notifications
Mule agent notificationsShanky Gupta
 
Mulesoft Consuming Web Service - Web Service Consumer
Mulesoft Consuming Web Service - Web Service ConsumerMulesoft Consuming Web Service - Web Service Consumer
Mulesoft Consuming Web Service - Web Service ConsumerVince Soliza
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with MuleBui Kiet
 
Mule jms queues
Mule jms queuesMule jms queues
Mule jms queuesGandham38
 
Mule concepts
Mule conceptsMule concepts
Mule conceptsSindhu VL
 
Message properties component in Mule
Message properties component in MuleMessage properties component in Mule
Message properties component in MuleKhan625
 
Using groovy in mule
Using groovy in muleUsing groovy in mule
Using groovy in muleSon Nguyen
 
Until successful component in mule demo
Until successful component in mule demoUntil successful component in mule demo
Until successful component in mule demoSudha Ch
 
Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in muleMohammed246
 

What's hot (20)

Mule Webservices
Mule WebservicesMule Webservices
Mule Webservices
 
Xslt in mule
Xslt in muleXslt in mule
Xslt in mule
 
Mule integration
Mule integrationMule integration
Mule integration
 
Introduction To Mule
Introduction To MuleIntroduction To Mule
Introduction To Mule
 
Connectors in mule
Connectors in muleConnectors in mule
Connectors in mule
 
Mule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce InterfaceMule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce Interface
 
Mule agent notifications
Mule agent notificationsMule agent notifications
Mule agent notifications
 
Mule soa
Mule soaMule soa
Mule soa
 
Quartz in Mule
Quartz in MuleQuartz in Mule
Quartz in Mule
 
Mule Message Properties Component
Mule Message Properties ComponentMule Message Properties Component
Mule Message Properties Component
 
Mulesoft Consuming Web Service - Web Service Consumer
Mulesoft Consuming Web Service - Web Service ConsumerMulesoft Consuming Web Service - Web Service Consumer
Mulesoft Consuming Web Service - Web Service Consumer
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with Mule
 
Mule batch job
Mule batch jobMule batch job
Mule batch job
 
Mule advanced
Mule advancedMule advanced
Mule advanced
 
Mule jms queues
Mule jms queuesMule jms queues
Mule jms queues
 
Mule concepts
Mule conceptsMule concepts
Mule concepts
 
Message properties component in Mule
Message properties component in MuleMessage properties component in Mule
Message properties component in Mule
 
Using groovy in mule
Using groovy in muleUsing groovy in mule
Using groovy in mule
 
Until successful component in mule demo
Until successful component in mule demoUntil successful component in mule demo
Until successful component in mule demo
 
Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in mule
 

Similar to Send email attachment using smtp in mule esb

Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esbRaviShankar Mishra
 
Send email attachment using smtp in mule esb
Send email attachment using smtp  in mule esbSend email attachment using smtp  in mule esb
Send email attachment using smtp in mule esbAnand kalla
 
Email configuration in mule esb
Email configuration in mule esbEmail configuration in mule esb
Email configuration in mule esbVamsi Krishna
 
Mule connectors-part 1
Mule connectors-part 1Mule connectors-part 1
Mule connectors-part 1VirtusaPolaris
 
Adding dynamic file
Adding dynamic fileAdding dynamic file
Adding dynamic fileSon Nguyen
 
File component in mule demo
File component in mule demoFile component in mule demo
File component in mule demoSudha Ch
 
Mule ESB Components
Mule ESB Components Mule ESB Components
Mule ESB Components pat_91
 
XML Tutor maXbox starter27
XML Tutor maXbox starter27XML Tutor maXbox starter27
XML Tutor maXbox starter27Max Kleiner
 
File component in mule
File component in muleFile component in mule
File component in muleRajkattamuri
 
File component
File component File component
File component F K
 
File component in mule
File component in muleFile component in mule
File component in mulejaveed_mhd
 

Similar to Send email attachment using smtp in mule esb (20)

Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
 
Send email attachment using smtp in mule esb
Send email attachment using smtp  in mule esbSend email attachment using smtp  in mule esb
Send email attachment using smtp in mule esb
 
Email configuration in mule esb
Email configuration in mule esbEmail configuration in mule esb
Email configuration in mule esb
 
Mule connectors-part 1
Mule connectors-part 1Mule connectors-part 1
Mule connectors-part 1
 
Mule connectors-session1
Mule connectors-session1Mule connectors-session1
Mule connectors-session1
 
Adding dynamic file
Adding dynamic fileAdding dynamic file
Adding dynamic file
 
File component in mule demo
File component in mule demoFile component in mule demo
File component in mule demo
 
Mule ESB
Mule ESBMule ESB
Mule ESB
 
Mule ESB Components
Mule ESB Components Mule ESB Components
Mule ESB Components
 
Mule esb
Mule esbMule esb
Mule esb
 
XML Tutor maXbox starter27
XML Tutor maXbox starter27XML Tutor maXbox starter27
XML Tutor maXbox starter27
 
mulesoft
mulesoftmulesoft
mulesoft
 
File component
File component File component
File component
 
Mule File component
Mule File component Mule File component
Mule File component
 
File component in mule
File component in muleFile component in mule
File component in mule
 
File component
File component File component
File component
 
File component in mule
File component in muleFile component in mule
File component in mule
 
File component
File componentFile component
File component
 
Dynamic file attribute
Dynamic file attributeDynamic file attribute
Dynamic file attribute
 
Splitter
SplitterSplitter
Splitter
 

More from Phaniu

Anypoint data gateway
Anypoint data gatewayAnypoint data gateway
Anypoint data gatewayPhaniu
 
Data weave
Data weave Data weave
Data weave Phaniu
 
How to use expression filter
How to use expression filterHow to use expression filter
How to use expression filterPhaniu
 
How to use message properties component
How to use message properties componentHow to use message properties component
How to use message properties componentPhaniu
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mulePhaniu
 
Mmc rest api user groups
Mmc rest api user groupsMmc rest api user groups
Mmc rest api user groupsPhaniu
 
Mule esb stripe
Mule esb stripeMule esb stripe
Mule esb stripePhaniu
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollectionPhaniu
 
Mule esb
Mule esbMule esb
Mule esbPhaniu
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollectionPhaniu
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollectionPhaniu
 
Mule esb
Mule esbMule esb
Mule esbPhaniu
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollectionPhaniu
 
Mule security jaas
Mule security jaasMule security jaas
Mule security jaasPhaniu
 
Mule security jaas
Mule security jaasMule security jaas
Mule security jaasPhaniu
 
Mule security saml
Mule security samlMule security saml
Mule security samlPhaniu
 
Mule soa
Mule soaMule soa
Mule soaPhaniu
 
Mule soap
Mule soapMule soap
Mule soapPhaniu
 

More from Phaniu (20)

Anypoint data gateway
Anypoint data gatewayAnypoint data gateway
Anypoint data gateway
 
Data weave
Data weave Data weave
Data weave
 
How to use expression filter
How to use expression filterHow to use expression filter
How to use expression filter
 
How to use message properties component
How to use message properties componentHow to use message properties component
How to use message properties component
 
Mapping and listing with mule
Mapping and listing with muleMapping and listing with mule
Mapping and listing with mule
 
Mmc rest api user groups
Mmc rest api user groupsMmc rest api user groups
Mmc rest api user groups
 
Mmc
MmcMmc
Mmc
 
Mmc 2
Mmc 2Mmc 2
Mmc 2
 
Mule esb stripe
Mule esb stripeMule esb stripe
Mule esb stripe
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollection
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollection
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollection
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule for each scope headerc ollection
Mule for each scope headerc ollectionMule for each scope headerc ollection
Mule for each scope headerc ollection
 
Mule security jaas
Mule security jaasMule security jaas
Mule security jaas
 
Mule security jaas
Mule security jaasMule security jaas
Mule security jaas
 
Mule security saml
Mule security samlMule security saml
Mule security saml
 
Mule soa
Mule soaMule soa
Mule soa
 
Mule soap
Mule soapMule soap
Mule soap
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Send email attachment using smtp in mule esb

  • 1. Send email attachment using SMTP in Mule ESB
  • 2. What is Mule ESB ?  Mule ESB is a lightweight Java-based enterprise service bus (ESB) and integration platform that allows developers to connect applications together quickly and easily, enabling them to exchange data. Mule ESB enables easy integration of existing systems, regardless of the different technologies that the applications use, including JMS, Web Services, JDBC, HTTP, and more.
  • 3.  This example shows how we can send email attachment using SMTP connector to self or another email. We simply put a file in a source directory and Mule will read the file from the source directory. Using Mule ESB it’s very easy to read the file from a location. If we had to read the file using manual coding then we had to write many lines of code. But using Mule ESB we just simply put a file in a directory and let the Mule know the file path and Mule does the rest of the thing. You can put any kind of file to the source for reading. The file that we put into a source directory will be an attachment to the intended recipient’s mail address. So finally when we will see the file as an attachment in the mailbox.
  • 4. What is Attachment transformer ?  Attachment transformer lets us attach a file or document which will be sent to the email address.
  • 5. What is SMTP connector ?  The SMTP endpoint allows Mule messages to be sent as email or email attachments with the Simple Mail Transfer Protocol (SMTP) using Java mail API.
  • 6. Prerequisites  Mule Studio 3.5.1 JDK 1.6 Maven 3 Mule Runtime 3.5.0 CE Knowledge of XML
  • 7.  Open Mule Studio and create a mule project. Go to File->New->Mule Project. Now enter the Project Name, selectRuntime – Mule Server, check the check box for Use Maven. Now enter the following information  Group Id: your Mail(ex. gmail.com) Artifact Id: project name – file- attachment(automatically populated when project name is getting typed) V  Click Next and verify project Location and JRE/JDK are set correctly. Click Finishersion: Mule studio generates default
  • 8.  Now drag and drop the elements from right side of the Mule studio as shown below in the picture.
  • 9.
  • 10. Browse and select the path from where a file will be read for an attachment. Logger component properties
  • 11.  File to String transformer properties  File-to-Strong transformer just transforms the file object to human readable string format. We will not set any property for this element Attachment transformer properties
  • 12.  Using attachment transformer we can set payload from previous flow as an attachment. We have to select Content Type, operation as Set Attachment, Name, Value
  • 13.  SMTP connector properties For SMTP connector we have to input email host, user name, password, port under Basic Settings and To Address, From Address, Subject under Email Information.
  • 14.  The whole XML file of entire flow  <?xml version="1.0" encoding="UTF-8"?>   <mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp"  xmlns:file="http://www.mulesoft.org/schema/mule/file" 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" version="CE-3.5.0"  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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd  http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">  <flow name="file-attachmentFlow1" doc:name="file-attachmentFlow1">  <file:inbound-endpoint path="D:AnypointWorkspacesource"  responseTimeout="10000" doc:name="File" />  <logger message="#[payload]" level="INFO" doc:name="Logger" />  <file:file-to-string-transformer  doc:name="File to String" />  <logger message="#[payload]" level="INFO" doc:name="Logger" />  <set-attachment attachmentName="attachment" value="#[payload]"  contentType="text/plain" doc:name="Attachment" />  <logger message="#[payload]" level="INFO" doc:name="Logger" />  <smtp:outbound-endpoint host="mail.domain.com"  user="emailAddress@domain.com" password="password" to="emailAddress@domain.com"  from="emailAddress@domain.com" subject="Test Email" responseTimeout="10000"  doc:name="SMTP" />  <logger message="#[payload]" level="INFO" doc:name="Logger" />  </flow>  </mule>
  • 15.  Now create a text file called file- attachment.txt and put it under selected path, i.e., as per the above XML the file path is D:AnypointWorkspacesource.  Do right-click on file-attachment.xml and click on Run As -> Mule Application with Maven. Once the application up and running you will get the console output and email attachment in your mailbox where you have sent the email.
  • 16.  Output in console  INFO 2015-03-05 09:25:46,372 [[file- attachment].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: D:AnypointWorkspacesourcefile-attachment.txt  INFO 2015-03-05 09:25:46,404 [[file-attachment].file- attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: org.mule.transport.file.ReceiverFileInputStream@6a150e  INFO 2015-03-05 09:25:46,406 [[file-attachment].file- attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: This is a file content  INFO 2015-03-05 09:25:46,407 [[file-attachment].file- attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: This is a file content  INFO 2015-03-05 09:25:46,419 [[file-attachment].file- attachmentFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: This is a file content  INFO 2015-03-05 09:25:46,422 [[file- attachment].connector.smtp.mule.default.dispatcher.01] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.email.transformers.ObjectToMimeMessage  INFO 2015-03-05 09:25:46,428 [[file- attachment].connector.smtp.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.smtp.mule.default.dispatcher.1213248'. Object is: SmtpMessageDispatcher
  • 17.  Click on the attachment. You will see the below output in the browser.