This is a minimal application sending emails with Gmail. It generates the email body with a Qute template.
-
You need to generate an application password to use GMail from the application. Follow these instructions to create the password.
-
You need Java 1.8+. However, we recommend Java 11+.
-
You need GraalVM and
native-image
installed and configured. Follows the instructions to download, install, and configure GraalVM.
Launch the Maven build on the checked-out sources of this demo:
> ./mvnw package
Generate the native executable using:
> ./mvnw package -Dnative
The application contains tests that used the mock mailer to avoid sending actual emails during the tests. The dev mode also uses this mock mailer.
The application uses GMAIL. Define the following environment properties:
QUARKUS_MAILER_USERNAME
- your Google email addressQUARKUS_MAILER_FROM
- your Google email address (or alias)QUARKUS_MAILER_PASSWORD
- the application password generated above
Run the application with:
> java -jar ./target/quarkus-app/quarkus-run.jar
Thanks to the environment properties defined above, the application should authenticate with Gmail and send the email.
To send the email, use the /mail
endpoint.
If you have the httpie command line, you can run:
http :8080/mail name==some-name email==target-email-address
You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM: everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.
Compiling a native executable takes a bit longer, as GraalVM performs additional
steps to remove unnecessary code paths. Use the native
profile to compile a
native executable:
> ./mvnw package -Dnative
After getting a cup of coffee, you'll be able to run this executable directly:
> ./target/mailer-quickstart-1.0.0-SNAPSHOT-runner
Then send an email using the same http command.