Enable to initialize Simple Java Mail with a Config configuration.
Configuration parameters are listed at http://www.simplejavamail.org/#section-available-properties.
All properties prefixed by mail
are converted to simplejavamail
properties.
For example:
mail."smtp.host" = "127.0.0.1"
mail."smtp.port" = 25
mail."defaults.from.address" = "[email protected]"
Will be passed to Simple Java Mail as:
simplejavamail.smtp.host=127.0.0.1
simplejavamail.smtp.port=25
simplejavamail.defaults.from.address[email protected]
You should noticed that in the Config configuration, Simple Java Mail properties are wrapped in quotes. This is important, else mail properties will be ignored.
Include Plume Mail in your project:
<dependency>
<groupId>com.coreoz</groupId>
<artifactId>plume-mail</artifactId>
</dependency>
Install Guice module: install(new GuiceMailModule());
Configure the Mailer default properties in your application.conf
file:
mail."smtp.host" = "127.0.0.1"
mail."smtp.port" = 25
mail."defaults.from.address" = "[email protected]"
Create a mail service class that sends mails:
@Singleton
public class EmailService {
private final Mailer mailer;
@Inject
public EmailService(Mailer mailer) {
this.mailer = mailer;
}
public void sendEmail() {
Email email = EmailBuilder
.startingBlank()
.to("Russell Powell", "[email protected]")
.withSubject("Plume")
.withPlainText("You should check this Java library out!")
.buildEmail();
mailer.sendMail(email, true);
}
}