SlideShare a Scribd company logo
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.
Send email attachment using smtp  in mule esb
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

PPTX
Creating restful api using mule esb
PPTX
Integration with Dropbox using Mule ESB
ODP
Mule ESB SMTP Connector Integration
PPTX
Send email attachment using smtp in mule esb
PPTX
Soap request in mule
PPTX
Mule Esb Data Weave
PPTX
Message properties component in Mule
PPT
Anypoint connectorfor ibm as 400
Creating restful api using mule esb
Integration with Dropbox using Mule ESB
Mule ESB SMTP Connector Integration
Send email attachment using smtp in mule esb
Soap request in mule
Mule Esb Data Weave
Message properties component in Mule
Anypoint connectorfor ibm as 400

What's hot (15)

PPTX
Mulesoft http connector
PPTX
Send email attachment using smtp in mule esb
PPTX
Mule Webservices
PPTX
Mule Message Properties Component
PPTX
Xslt in mule
PPTX
Splitting with mule part2
PPTX
Stored procedure in Mule
PPTX
Mule ESB - Mock Salesforce Interface
PPTX
Mule soap
PPT
Mule - HTTP Listener
PPTX
Choice component in mule
PPTX
Mule esb
PPTX
Mule esb :Data Weave
PPTX
Mule esb add logger to existing flow
PPTX
Configurare http mule
Mulesoft http connector
Send email attachment using smtp in mule esb
Mule Webservices
Mule Message Properties Component
Xslt in mule
Splitting with mule part2
Stored procedure in Mule
Mule ESB - Mock Salesforce Interface
Mule soap
Mule - HTTP Listener
Choice component in mule
Mule esb
Mule esb :Data Weave
Mule esb add logger to existing flow
Configurare http mule
Ad

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

PPTX
Send email attachment using smtp in mule esb
PPTX
Email using mule
PPTX
Send email attachment using smtp in mule esb
PPTX
Email configuration in mule esb
PPTX
SMTP MULE
PPTX
How to use smtp endpoint
ODP
Mule smtp connector
PPTX
How to use attachment transformer
PPTX
Sending mail with attachment
PDF
MuleSoft Surat Live Demonstration Virtual Meetup#3 - Building JWT OAuth 2.0 C...
PPTX
Sending mail in mule
PPTX
Imap connector
PPTX
File component in mule demo
PPTX
Imap connector
PPTX
Mule enterprise service introduction
PPTX
File connector
PPTX
File Connector
PPTX
File component
PDF
Mule ESB Interview or Certification questions
PPTX
File component
 
Send email attachment using smtp in mule esb
Email using mule
Send email attachment using smtp in mule esb
Email configuration in mule esb
SMTP MULE
How to use smtp endpoint
Mule smtp connector
How to use attachment transformer
Sending mail with attachment
MuleSoft Surat Live Demonstration Virtual Meetup#3 - Building JWT OAuth 2.0 C...
Sending mail in mule
Imap connector
File component in mule demo
Imap connector
Mule enterprise service introduction
File connector
File Connector
File component
Mule ESB Interview or Certification questions
File component
 
Ad

More from princeirfancivil (20)

PPTX
Web services uddi
PPTX
Web services wsdl
PPTX
Web services SOAP
PPTX
WebServices introduction
PPTX
Introduction to java
PPTX
Building and managing java projects with maven part-III
PPTX
PPTX
Maven part 1
PPT
Anypoint data gateway
PPTX
Data weave
PPTX
How to use expression filter
PPTX
How to use message properties component
PPTX
Mapping and listing with mule
PPTX
Mmc rest api user groups
PPTX
PPT
Mule esb api layer
PPTX
Mule esb stripe
PPTX
Web services uddi
Web services wsdl
Web services SOAP
WebServices introduction
Introduction to java
Building and managing java projects with maven part-III
Maven part 1
Anypoint data gateway
Data weave
How to use expression filter
How to use message properties component
Mapping and listing with mule
Mmc rest api user groups
Mule esb api layer
Mule esb stripe

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm

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.
  • 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.