DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

A dedicated IT Architect specializing in SOA, Java and Web development for hospitality industry with strong experience in designing SOA architectures, solving complex integration problems and leading Agile teams to hit deadlines. At the moment I work for Grupo Vidanta, one of the most important hospitality corporations in Mexico and Latin America. I like to design and develop great solutions, apps and much more, also I enjoy creating prototypes with the newest technologies, just remember "If you can imagine it, you can develop it" ... Marco has posted 1 posts at DZone. You can read more from them at their website. View Full User Profile

Gmail Service In Mule ESB

  • submit to reddit


The following example shows how to expose a SOAP service that send a mail using the SMTP outbound and the Gmail connector.

GmailService-config.xml (mule-config.xml file)

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="" xmlns:http=""
	xmlns:cxf="" xmlns:context=""
	xmlns:smtps="" xmlns:smtp=""
	xmlns:spring="" xmlns:core=""
	xmlns:xsi="" version="CE-3.3.0"
	xsi:schemaLocation=" ">
	     The Gmail connector is part of connectors that Mule ESB offers out of the box.
	<smtp:gmail-connector name="emailConnector"
		doc:name="Gmail" />
	     The flows starts here
	<flow name="GMailService-configFlow1" doc:name="GMailService-configFlow1">
	    Configuring the HTTP inbound 
		<http:inbound-endpoint exchange-pattern="request-response"
			address="http://localhost:9094/gmailService" doc:name="HTTP" />
	     In this block the SOAP CXF Service is configured. We need two java classes one is for
	     set up the Simple Front end of the Web Service and the other one is for return the payload
	     to the flow, in this case the mail that we want to send. 
		<cxf:jaxws-service serviceClass=""
			doc:name="IGmailService" enableMuleSoapHeaders="false"/>
		<component class="" doc:name="GMailService" />
		<object-to-string-transformer doc:name="Object to String" />
	     We generate a response for the SOAP Service.
			<set-payload value="Your Message has been sent."
				doc:name="Set Payload" />
		<logger message="******** #[payload]" level="INFO" doc:name="Logger" doc:description="Just for log the message to send"/>
		<echo-component doc:name="Echo" />
	     Setting the outbound 
	     Note that the user has to be set up with an "%40" instead of "@" otherwise the 
	     SMTP outbound wont work, and you'll have to do the same for the password all 
	     the @'s wont wont work.   
		<smtps:outbound-endpoint host="" user=""
			password="THE_PASSWORD" from="" subject="Email from Mule ESB"
			doc:name="Send notification email" to="" />

In resume a simple CXF service is being exposed to send some text through Gmail.

The class is used to return the payload to Mule’s flow.

An Echo component is added to generate the response flow, and a SetPayload Transformer is placed to generate the response text.

The Logger component is useful to keep a track of the message that you want to send.

You have to consider the following things before you test the service:

  • The “user” attribute uses the escape code of “%40″ to replace the “@” symbol.
  • As the “user attribute the “password” needs ”%40″ escape code too every time you want to place an “@”.
  • Note that in “from” and “to” attributes the “@” symbol will work perfectly.

import javax.jws.WebMethod;
import javax.jws.WebService;
public interface IGmailService {
	@WebMethod(operationName = "sendMail")
	public String sendMail(String text);

This will expose a simple CXF service in Mule ESB with a method called "sendMail" that accept a String as input.

public class GmailService implements IGmailService {
	public String sendMail(String text) {
		return text;

This class returns the text that was passed through the Web Service to the Mule's payload.

You can find the project in Github here .