Skip to content

Latest commit

 

History

History
114 lines (72 loc) · 3.69 KB

File metadata and controls

114 lines (72 loc) · 3.69 KB

Getting started with the Quarkus Mailer

This is a minimal application sending emails with Gmail. It follows the instructions from the getting started guide, but also contains some extra examples:

Prerequisites

  1. You need to generate an application password to use GMail from the application. Follow these instructions to create the password.

  2. You need Java 11+.

  3. You need GraalVM and native-image installed and configured. Follows the instructions to download, install, and configure GraalVM.

Building the application

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.

Configuring the application

The application uses GMAIL. Define the following environment properties:

  • QUARKUS_MAILER_USERNAME - your Google email address
  • QUARKUS_MAILER_FROM - your Google email address (or alias)
  • QUARKUS_MAILER_PASSWORD - the application password generated above

Running the application in JVM mode

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.

Before doing so:

  1. Change the email address used in src/main/java/org/acme/MailResource.java, so you can receive the email
  2. If you want to send an email (and not just simulate it), add quarkus.mailer.mock=false to the src/main/resources/application.properties file

Then, in a terminal use

curl -v :8080/mail

Running the application as a native executable

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 curl command.

Other demos

Before running the other demos, don't forget to edit the code to use your email address.

Using attachments

Using template

Using type-safe template