Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

build test deploy Maven Central

bootique-simplejavamail

Provides Simple Java Mail integration with Bootique.

Usage

Include bootique-bom:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.bootique.bom</groupId>
            <artifactId>bootique-bom</artifactId>
            <version>2.0.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Import Simple Java Mail integration:

<dependency>
	<groupId>io.bootique.simplejavamail</groupId>
	<artifactId>bootique-simplejavamail</artifactId>
</dependency>

Configure the app:

simplejavamail:

  # Mail delivery is disabled by default to prevent inadvertent spamming when the app is in development. This property
  # needs to be flipped to "false" if you want mail to be actually sent to someone.
  disabled: false

  # Configure named mailers. If "mailers" section is absent, the default mailer is created pointing to "localhost:25"
  mailers:
    main: # arbitrary name of the mailer
      smtpServer: example.org
      smtpPort: 3025
      transportStrategy: SMTPS

Send mail:

@Inject
Mailers mailers;

public void sendMail() {
    Email email = EmailBuilder.startingBlank()
        .from("me@example.org")
        .to("you@example.org")
        .withSubject("Hi!")
        .withPlainText("Hello world..")
        .buildEmail();

    // if only one mailer is configured in YAML, it is assumed to be the default mailer
    mailers.getDefaultMailer().sendMail(email, false);
}