apache camel
Creating a component from archetype
Sending email (gmail) by camel routes
Enable gmail app passwords.
Enable 2-step-verification (following verification through SMS).
Generate a password for the camel app (selecting app "Mail" and a device type or custom). It will venerate a 16 characters password for the camel app.
Make sure the app is set up for camel-mail component.
Set up a camel route
Set the consumer side ('from' of camel route).
Set a message subject, recipient and body.
Set the producer side (mail following gmail smtp configuration).
Use secure smtp on port 465 (smtps://smtp.gmail.com:465).
Set the username as a valid gmail address (ex: username=myuser@gmail.com).
Set the 16 characters generated app password (ex: password=abcd1234abcd5678).
Set smtp authentication (mail.smtp.auth=true).
Set STARTTLS as enabled (mail.smtp.starttls.enable=true).
Example:
<routes xmlns="http://camel.apache.org/schema/spring" >
<route id="sendMail">
<from uri="jason:toEmail" />
<setBody>
<!-- remove quotes -->
<simple>${body.replaceAll("\u0022","")}</simple>
</setBody>
<setHeader headerName="Subject">
<simple>${in.body}</simple>
</setHeader>
<setHeader headerName="To">
<constant>recipient@gmail.com</constant>
</setHeader>
<setBody>
<simple>${in.body}\nHi, Some message.\n</simple>
</setBody>
<!-- gmail configuration -->
<to uri="smtps://smtp.gmail.com:465?username=myuser@gmail.com&password=abcd1234abcd5678&debugMode=true&mail.smtp.auth=true&mail.smtp.starttls.enable=true"/>
</route>
</routes>
Last updated
Was this helpful?