Loading

Send Email from Mule 4 Using a Gmail App Password

Data pubblicazione: Oct 27, 2026
Operazione

GOAL

Generate an app password for a Gmail account and use it in an Email Connector SMTP configuration to send email from a Mule 4 application.

When you use Email Connector with a username and password, Google requires an app password with 2-Step Verification turned on. Google doesn't offer app passwords for work, school or organization accounts, for accounts with Advanced Protection, or for accounts that use 2-Step Verification with security keys only. For new integrations, consider OAuth 2.0 with Gmail Connector, which Google prefers for Gmail API access.

Fasi

Generate the Gmail App Password

  1. Turn on 2-Step Verification for the Gmail account at https://myaccount.google.com/signinoptions/two-step-verification.
  2. Open https://myaccount.google.com/apppasswords. Sign in to the Google account if prompted.
  3. Enter an app name, for example Mule Application, and create the password.
  4. Copy and save the generated app password. Google shows it only once: if you lose it, generate a new one. Google also revokes all app passwords when the Google account password changes.

Configure the Mule Application

  1. Define an SMTP configuration that connects to smtp.gmail.com on port 587 with STARTTLS enabled:
    <email:smtp-config name="Email_SMTP" doc:name="Email SMTP">
    	<email:smtp-connection host="smtp.gmail.com" port="587" user="SenderAccount@gmail.com" password="App_password" >
    		<email:properties >
    			<email:property key="mail.smtp.starttls.enable" value="true" />
    		</email:properties>
    	</email:smtp-connection>
    </email:smtp-config>
    Replace SenderAccount@gmail.com with the Gmail address and App_password with the generated app password. Port 587 requires STARTTLS. If mail.smtp.starttls.enable isn't set to true, smtp.gmail.com returns this error:
    530 5.7.0 Must issue a STARTTLS command first
    To use SSL on port 465 instead, use an SMTPS connection as shown in Connect to Gmail with Email Connector Examples.
  2. In the flow that sends mail, add an Email Send operation that references the SMTP configuration, for example:
    <email:send doc:name="Send" config-ref="Email_SMTP" fromAddress="SenderAccount@gmail.com" subject="Sending a gmail!">
    	<email:to-addresses >
    		<email:to-address value="RecipientAccount@gmail.com" />
    	</email:to-addresses>
    	<email:reply-to-addresses >
    		<email:reply-to-address value="SenderAccount@gmail.com" />
    	</email:reply-to-addresses>
    	<email:body contentType="text/plain">
    		<email:content ><![CDATA[#["Sending a gmail!"]]]></email:content>
    	</email:body>
    	<email:attachments/>
    </email:send>
    Replace SenderAccount@gmail.com and RecipientAccount@gmail.com with actual addresses.
  3. Run the Mule application and test the flow that sends mail.

TROUBLESHOOTING

If Gmail rejects the login with "Application-specific password required" or "Username and Password not accepted", check that 2-Step Verification is on and that the configuration uses a current app password, not the Google account password.

To see the SMTP conversation for other send errors, turn on JavaMail debug logging by adding the mail.debug property to the SMTP connection properties:

<email:properties >
	<email:property key="mail.smtp.starttls.enable" value="true" />
	<email:property key="mail.debug" value="true" />
</email:properties>

For Mule applications deployed to CloudHub 2.0, also set the application property forwardConsoleLogToAnypointMonitoring.enable=true so the SMTP debug logs are captured. For more details, see Troubleshooting Email Connector.

Numero articolo Knowledge

001116984

 
Caricamento
Salesforce Help | Article