Contact Free trial Login

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.

Enable Less Secure Apps in Your Gmail Account

Google might block third-party mail clients if you do not enable the Less Secure Apps setting for your Gmail account, because Google blocks any apps that are not using security protocols that Google deems mandatory unless you allow less secure apps to access your Gmail account.

When you try to connect to your Gmail for the first time, you will receive an email with a link for enabling less secure apps in your Gmail account.

Email notification from Google about the blocked sign-in attempt

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 the Filter field, 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.

The following screenshot shows the configuration:

IMAPs Configuration to Gmail
Figure 1. IMAPS Configuration to Gmail

In the XML editor, the configuration looks like this:

<email:imap-config name="Email_IMAP">
  <email:imaps-connection host="imap.gmail.com"
    port="993" 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 the Filter field, 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
      993

    • User
      user@gmail.com

    • Password
      Gmailpassword

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

  7. Click OK.

The following screenshot shows the configuration:

POP3S Configuration to Gmail
Figure 2. POP3S Configuration to Gmail

In the 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 the Filter field, 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.

The following screenshot shows the configuration:

SMTPS Configuration to Gmail
Figure 3. SMTPS Configuration to Gmail

In the 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.