By default the plugin automatically configure the injected instances with the application.conf
file:
class MyComponent @Inject() (mailer: MailerClient) {
// ...
}
If you want to configure the injected instances from another source, you will need to override the default provider:
-
Create a custom configuration provider:
CustomSMTPConfigurationProvider.scalaclass CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] { override def get() { // Custom configuration new SMTPConfiguration("typesafe.org", 1234) } } class CustomMailerConfigurationModule extends Module { def bindings(environment: Environment, configuration: Configuration) = Seq( bind[SMTPConfiguration].toProvider[CustomSMTPConfigurationProvider] ) }
-
Override the default provider in the
application.conf
file:application.confplay { modules { # Disable the default provider disabled += "play.api.libs.mailer.SMTPConfigurationModule" # Enable the custom provider (see above) enabled += "controllers.CustomMailerConfigurationModule" } }
You can also use the SMTPMailer
constructor to create new instances with custom configuration:
val email = Email("Simple email", "Mister FROM <[email protected]>")
new SMTPMailer(SMTPConfiguration("typesafe.org", 1234)).send(email)
new SMTPMailer(SMTPConfiguration("playframework.com", 5678)).send(email)