Contact Us 1-800-596-4880

Connect to Gmail with Email Connector Examples - Mule 4

To connect Anypoint Connector for Email (Email Connector) to your Gmail account, enable Less Secure Apps in your account and configure a global element for the server connection IMAPS, POP3S, or SMTPS you want to use.

Configure an App Password in Your Gmail Account

To send emails to a Gmail account via Email Connector, you must configure an app password in your Gmail account.

Use the app password instead of your regular Gmail email password, which enables you to use email protected by MFA (Multi-Factor Authentication).

Configure an IMAPS Connection

To connect Email Connector to your Gmail account using an IMAPS connection, configure a global element:

  1. In Studio, navigate to the Global Elements view.

  2. Click Create to open the Choose Global Type view.

  3. In Filter, type email, select Email IMAP, and click OK.

  4. In the Email IMAP window, for the Connection field, select IMAPS Connection.

  5. In the General section, enter the following values:

    • Host imap.gmail.com

    • Port 993

    • User user@gmail.com

    • Password Gmailpassword

  6. In the Trust Store Configuration section, select the Insecure checkbox.

  7. Click OK.

IMAPs Configuration to Gmail

In the Configuration XML editor, the configuration looks like this:

<email:imap-config name="Email_IMAP">
  <email:imaps-connection host="imap.gmail.com"
    port="995" user="user@gmail.com"
    password="mypassword">
    <tls:context>
        <tls:trust-store insecure="true"/>
    </tls:context>
  </email:imaps-connection>
</email:imap-config>

Configure a POP3S Connection

To connect Email Connector to your Gmail account using a POP3S connection, configure a global element:

  1. In Studio, navigate to the Global Elements view.

  2. Click Create to open the Choose Global Type view.

  3. In Filter, type email, select Email POP3, and click OK.

  4. In the Email POP3 window, for the Connection field, select POP3S Connection.

  5. In the General section, enter the following values:

    • Host pop.gmail.com

    • Port 995

    • User user@gmail.com

    • Password Gmailpassword

  6. In the Trust Store Configuration section, select the Insecure checkbox.

  7. Click OK.

POP3S Configuration to Gmail

In the Configuration XML editor, the configuration looks like this:

<email:pop3-config name="Email_POP3">
    <email:pop3s-connection host="pop.gmail.com"
      port="995"  user="user@gmail.com"
      password="Gmailpassword">
        <tls:context>
            <tls:trust-store insecure="true"/>
        </tls:context>
    </email:pop3s-connection>
</email:pop3-config>

Configure an SMTP Connection

To connect Email Connector to your Gmail account using an SMTPS connection, configure a global element:

  1. In Studio, navigate to the Global Elements view.

  2. Click Create to open the Choose Global Type view.

  3. In Filter, type email, select Email SMTP, and click OK.

  4. In the Email SMTP window, for the Connection field, select SMTPS Connection.

  5. In the General section, enter the following values:

    • Host smtp.gmail.com

    • Port 465

    • User user@gmail.com

    • Password Gmailpassword

  6. In the Trust Store Configuration section, select the Insecure checkbox.

  7. Click OK.

SMTPS Configuration to Gmail

In the Configuration XML editor, the configuration looks like this:

<email:smtp-config name="Email_SMTP" from="sender@gmail.com">
    <email:smtps-connection host="smtp.gmail.com"
      port="465" password="Gmailpassword"
      user="user@gmail.com">
        <tls:context enabledProtocols="TLSv1.2,SSLv3">
            <tls:trust-store insecure="true"/>
        </tls:context>
    </email:smtps-connection>
</email:smtp-config>

Troubleshoot SMTPS Connection Issues

The method that you use to troubleshoot SMTPS connection issues depends on whether or not your Gmail account uses two-factor authentication:

  • If your account uses two-factor authentication, generate an app-specific password and use that instead of your normal password.

    See Sign in Using App Password for details. You do not need to enable Less Secure Apps in your Gmail account.

  • If your Gmail account does not use two-factor authentication, set up and enable Less Secure Apps in your Gmail account, and if your password does not work, go to Allow Access to Your Google Account and follow these steps:

    1. Enter your username and password.

    2. Enter the letters on the captcha screen.

    3. Return to your Mule app and rerun the flow.

View on GitHub