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.
<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 firstTo use SSL on port 465 instead, use an SMTPS connection as shown in Connect to Gmail with Email Connector Examples.
<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.
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.
001116984

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.