<flow name="EmailNotificationService">
<vm:inbound-endpoint path="emailNotification" exchange-pattern="one-way" />
<smtps:outbound-endpoint user="${user}" password="${password}" host="${host}" from="${from}"
subject="Your order has been placed!">
<custom-transformer class="org.mule.example.bookstore.transformers.OrderToEmailTransformer" />
<email:string-to-email-transformer />
</smtps:outbound-endpoint>
</flow>
Email Transport Reference
Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version. |
The email transport is comprised of several transports for email connectivity. The implementation supports CC/BCC/ReplyTo addresses, attachments, custom Header properties and customizable authentication. See each email transport page for more details.
Configuration Examples
Here is a configuration snippet from the bookstore example. This flow is triggered when you send a string to vm://emailNotification and sends an order verification email to a specified address:
Here is a configuration snippet from the errorhandler example. This endpoint takes a ErrorMessageToExceptionBean java object and converts it to an email to a specified address:
<smtp:outbound-endpoint user="${smtp.username}" password="${smtp.password}"
host="${smtp.host}" port="${smtp.port}"
to="${email.toAddress}" from="${email.fromAddress}"
subject="${email.subject}">
<transformer ref="ErrorMessageToExceptionBean" />
<transformer ref="ExceptionBeanToXML" />
<email:string-to-email-transformer/>
</smtp:outbound-endpoint>
You can find full working configuration examples in each transport reference page.
The full example code for the bookstore and errorhandler examples are included in the full Mule ESB distribution.
Filters
Filters can be set on an endpoint to filter out any unwanted messages. The Email transport provides filters you can use directly or extended to implement custom filtering rules.
Filter | Description |
---|---|
org.mule.providers.email.filters.AbstractMailFilter |
A base filter implementation that must be extended by any other mail filter. |
org.mule.providers.email.filters.MailSubjectRegExFilter |
Applies a regular expression to a Mail Message subject. |
This is how you define the MailSubjectRegExFilter in your Mule configuration:
<message-property-filter pattern="to=barney@mule.org"/>
The \'pattern' attribute is a regular expression pattern. This is defined as java.util.regex.Pattern.
Email Transport
The email transport supplies various email connectivity options.
Transformers
These are transformers specific to this transport. Note that these are added automatically to the Mule registry at start up. When doing automatic transformations these will be included when searching for the correct transformers.
Name | Description |
---|---|
email-to-string-transformer |
Converts an email message to string format. |
string-to-email-transformer |
Converts a string message to email format. |
object-to-mime-transformer |
Converts an object to MIME format. |
mime-to-bytes-transformer |
Converts a MIME message to a byte array. |
bytes-to-mime-transformer |
Converts a byte array message to MIME format. |
Define transformers in your Mule configuration file:
<email:bytes-to-mime-transformer encoding="" ignoreBadInput="" mimeType="" name="" returnClass="" xsi:type=""/>
<email:email-to-string-transformer encoding="" ignoreBadInput="" mimeType="" name="" returnClass="" xsi:type=""/>
<email:mime-to-bytes-transformer encoding="" ignoreBadInput="" mimeType="" name="" returnClass="" xsi:type=""/>
<email:object-to-mime-transformer encoding="" ignoreBadInput="" mimeType="" name="" returnClass=""
useInboundAttachments="true" useOutboundAttachments="true"/>
<email:string-to-email-transformer encoding="" ignoreBadInput="" mimeType="" name="" returnClass="" xsi:type=""/>
Each transformer supports all the common transformer attributes and properties:
Transformer
A reference to a transformer defined elsewhere.
Name | Type | Required | Default | Description |
---|---|---|---|---|
ref |
string |
yes |
The name of the transformer to use. |
Name | Cardinality | Description |
---|
The object-to-mime-transformer
has the following attributes:
Attribute | Description | Default Value |
---|---|---|
useInboundAttachments |
Whether to transform inbound attachment in the input message into MIME parts. |
true |
useOutboundAttachments |
Whether to transform outbound attachment in the input message into MIME parts. |
true |
To use these transformers, make sure you include the 'email' namespace in your Mule configuration.