GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — quarkus-quickstarts/mailer-quickstart at main · JavaGreenHands/quarkus-quickstarts

Expand file tree

/

mailer-quickstart

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

mailer-quickstart

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
.mvn/wrapper
.mvn/wrapper
 
 
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
mvnw
mvnw
 
 
mvnw.cmd
mvnw.cmd
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Getting started with the Quarkus Mailer

  • Quarkus guide: https://quarkus.io/guides/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:

  • using template
  • using type safe template
  • using attachments

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

  • Code: using attachments
  • Command: curl -v http://localhost:8080/extra/attachment

Using template

  • Code: using template
  • Template: template
  • Command: curl -v http://localhost:8080/extra/template

Using type-safe template

  • Code: using type safe template
  • Template: template
  • Command: curl -v http://localhost:8080/type-safe
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.