MuleSoft Outlook SMTP Integration: The Complete Guide

Integrating email capabilities into your enterprise applications is a total game-changer. It transforms a silent, backend process into a communicative assistant that can send alerts, notifications, or critical reports without anyone lifting a finger.

In this guide, we are going to break down exactly how to bridge SMTP with Outlook (Office 365) using MuleSoft. Whether you are automating system health alerts or sending project status updates, this integration is the standard way to get your MuleSoft application talking to the Microsoft ecosystem.


Prerequisites

Before we dive into the XML and logic, let's make sure your toolbox is ready. You will need:

  • MuleSoft Anypoint Studio installed and running.
  • A valid Outlook/Office 365 email account.
    Pro Tip: If your organization uses Two-Factor Authentication (2FA), you likely cannot use your regular password. You will need to generate an "App Password" from your Microsoft Account security settings.
  • A basic understanding of how MuleSoft flows work.

Step 1: Setting the Trigger (HTTP Listener)

Every automation needs a kick-start. We will use an HTTP Listener to act as our trigger. Think of this as installing a doorbell on your server; it waits for a specific "knock" (a web request) to start the email process.

We will configure this to listen on host 0.0.0.0 and port 8081.

XML Configuration

Copy the code below into your Mule configuration file:

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
    <http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>

Step 2: Configuring the Outlook Engine

This is the engine room. We need to tell MuleSoft exactly how to handshake with Outlook's servers. Since we are using Office 365, strict security protocols are required.

We use the host smtp.office365.com and port 587.

Crucial Setting: You MUST ensure starttls.enable is set to "true". Without this, Office 365 will reject the connection because it requires a secure channel.

XML Configuration

Ensure you replace user-mail-address and user-mail-password with your actual credentials:

<email:smtp-config name="Email_SMTP_Outlook" doc:name="Email SMTP">
    <email:smtp-connection host="smtp.office365.com" port="587" user="user-mail-address" password="user-mail-password">
        <email:properties>
            <email:property key="mail.smtp.starttls.enable" value="true" />
            <email:property key="mail.smtp.connectiontimeout" value="60000" />
            <email:property key="mail.smtp.timeout" value="60000" />
            <email:property key="mail.smtp.writetimeout" value="60000" />
            <email:property key="mail.debug" value="true" />
        </email:properties>
    </email:smtp-connection>
</email:smtp-config>

Step 3: Building the Logic Flow

Now, let's stitch it all together. We will create a flow that accepts a POST request at the path /mail-send.

Inside the email body, we are using DataWeave to dynamically generate the current date and time. This is particularly useful for logging or time-sensitive notifications (formatted for IST in this example).

How it works:

  1. Listener: Receives the POST request from your browser or Postman.
  2. Email Send: Connects to Outlook using the config from Step 2. It constructs the body text using dynamic DataWeave expressions (`$(now())...`).
  3. Transform: Outputs the final payload as JSON so you get a clean response back.

XML Configuration

Paste this flow into your configuration XML. Note the DataWeave script embedded in the email body:

<flow name="smtp-integration-with-outlookFlow" doc:id="2447e40a-6e5e-4387-937e-6519c4dc453c">
    <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/mail-send" allowedMethods="POST" />
    <email:send doc:id="1bcb1998-a121-4c84-972d-b7a451451623" config-ref="Email_SMTP_Outlook"
        fromAddress="usermail-to-send-mail(user must have access to send a mail from to address)"
        toAddresses="#[from address mail list in array of item format ['mail1','mail2']]"
        subject="Exciting Opportunity: Join Our Real-Time Project Implementation Program!">
        <email:body contentType="text/plain">
            <email:content><![CDATA[#["Hi Team,

We hope this message finds you well.

I’m thrilled to announce that we have scheduled a sample real-time project implementation program. This is a fantastic opportunity for everyone.

Date: $(now() as Date{format:'EEEE MMMM dd'})
Time: $((now() >> 'IST') as Time{format:'hh:mm:ss.SSS Z a'})
Location: Hyderabad

Looking forward to an engaging and productive session with all of you!

Best regards,
Mail: [email protected]
Mule Trains."]]]></email:content>
        </email:body>
    </email:send>
    <ee:transform doc:name="Transform Message">
        <ee:message>
            <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
        </ee:message>
    </ee:transform>
</flow>

Conclusion

And that is it! You have successfully integrated SMTP with Outlook using MuleSoft. By following these specific configurations—especially the Office 365 host settings and TLS properties—you ensure a secure and reliable notification system for your app.

For the full source code and to see how this fits into a larger context, check out the project repository on GitHub: SMTP Integration with Outlook Project.

Post a Comment (0)
Previous Post Next Post