Friday, July 23, 2010

Sending outbound SMTP messages through Gmail with Mule ESB

I'm currently working on a Managed File Transfer (MFT) proof-of-concept for a client using Mule ESB Enterprise.  One of the requirements I had to address is the ability to send SMTP email messages when a particular connector failed, i.e. SFTP connection failed.  I thought to myself, that's a reasonable request and something that is probably straightforward to do in Mule ESB.  Well, if you look at the Mule configuration it is straightforward however, getting to that point using Gmail took some I thought I'd share :)

What you need...
  • Mule ESB (I'm using Mule ESB Enterprise Version: 2.2.5 Build: 16813 along with Mule Management Console support, i.e. mmc-agent-2.2.5.jar) *
  • A test Gmail account
* - if you plan on running the same version I am then there is a patch that needs to be applied to the mmc-agent-2.2.5.jar.  See JIRA issue MULE-4970.

Mule Configuration...
<?xml version="1.0"?>
<mule xmlns=""

  <description>Test configuration to send SMTP email through Gmail.</description>

  <!-- Configure some properties to work with GMail's SMTP -->
  <smtp:gmail-connector name="emailConnector" />

  <model name="processInboundFileModel">
    <service name="processInboundFileService">
<account name>"
<email addresses>"
<account name>"
            subject="Test email message"/>

As indicated, the Mule configuration is very straightforward.  You can get most of the information you need from the Mule SMTP Transport documentation except for what Gmail port to use and most importantly the gmail-connector information.  That tripped me up for a while until I came across a Mule JIRA issue where someone refer to the configuration in the bookstore example for sending email through Gmail.  I still haven't found much information on this connector and what it's doing but it does work and you need to use in order to connect to Gmail.

One other thing that is documented however maybe overlooked is that you need to replace the "@" symbol in the "user" attribute with the URL escape code of "%40".



Umashankar said...

Hi Rod Biresch

Thanks for the Article.
I need your help on one of my requirement.

I have email_requests in a table. I am reading the table rows from jdbc endpoints and sending the email to the users.
Now I want to update the same row with satus lets say if email fails then status of the row as 'ERROR' and if the email goes through, then status as 'COMPLETED'.

How Can I do this. How can I handle erros for SMTP end points.

Thanks in advance
Please reply to

Rod Biresch said...

Unfortunately, I have not had much time working with Mule ESB since the blog post. I suggest that you start with looking at Error Handler example in examples/errorhandler. I'm not sure if the SMTP transport can deal with mail failures or not. Chances are you will have to manually check your inbox (or use something like the POP3 Transport) for failures and process them accordingly.

Hope this helps!


Lacy Brown said...

Thanks for this great step by step process - I would like to use it for any new staff or children to our school in future. We have just begun our Blogging journey this year and this will certainly be useful to get the new users started in future! Thanks for sharing it with us.

To getGmail Technical Support, Please visit the link.

Thanks & Regards

Todd said...

This is cool!