GithubHelp home page GithubHelp logo

playframework / play-mailer Goto Github PK

View Code? Open in Web Editor NEW
248.0 24.0 73.0 797 KB

Play mailer plugin

License: Apache License 2.0

Scala 81.02% Java 18.98%
playframework play-framework scala java email-sender mailer

play-mailer's Introduction

Play Mailer

Twitter Follow Discord GitHub Discussions StackOverflow YouTube Twitch Status OpenCollective

Build Status Maven Repository size Scala Steward badge Mergify Status

Play Mailer is a powerful Scala Mailing library. It provides a simple configurable mailer.

Getting Started

To get started you add play-mailer and play-mailer-guice as a dependency in SBT:

libraryDependencies += "org.playframework" %% "play-mailer" % -version-
libraryDependencies += "org.playframework" %% "play-mailer-guice" % -version-

// Until version 9.x:
libraryDependencies += "com.typesafe.play" %% "play-mailer" % -version-
libraryDependencies += "com.typesafe.play" %% "play-mailer-guice" % -version-

Versioning

The Play Mailer plugin supports several different versions of Play.

Plugin version Play version
10.x 3.0.x
9.x 2.9.x
8.x 2.8.x
7.x 2.7.x

See GitHub releases for the latest versions.

After that you need to configure the mailer inside your application.conf:

play.mailer {
  host = "example.com" // (mandatory)
  port = 25 // (defaults to 25)
  ssl = no // (defaults to no)
  tls = no // (defaults to no)
  tlsRequired = no // (defaults to no)
  user = null // (optional)
  password = null // (optional)
  debug = no // (defaults to no, to take effect you also need to set the log level to "DEBUG" for the "play.mailer" logger)
  timeout = null // (defaults to 60s in milliseconds)
  connectiontimeout = null // (defaults to 60s in milliseconds)
  mock = no // (defaults to no, will only log all the email properties instead of sending an email)
  props {
    // Additional SMTP properties used by JavaMail. Can override existing configuration keys from above.
    // A given property will be set for both the "mail.smtp.*" and the "mail.smtps.*" prefix.
    // For a list of properties see:
    // https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html#properties

    // Example:
    // To set the local host name used in the SMTP HELO or EHLO command:
    // localhost = 127.0.0.1
    // Results in "mail.smtp.localhost=127.0.0.1" and "mail.smtps.localhost=127.0.0.1" in the JavaMail session.
  }
}

Usage

Scala

Runtime Injection

Use the @Inject annotation on the constructor, service of your component or controller:

import play.api.libs.mailer._
import java.io.File
import org.apache.commons.mail.EmailAttachment
import javax.inject.Inject

class MailerService @Inject() (mailerClient: MailerClient) {

  def sendEmail = {
    val cid = "1234"
    val email = Email(
      "Simple email",
      "Mister FROM <[email protected]>",
      Seq("Miss TO <[email protected]>"),
      // adds attachment
      attachments = Seq(
        AttachmentFile("attachment.pdf", new File("/some/path/attachment.pdf")),
        // adds inline attachment from byte array
        AttachmentData("data.txt", "data".getBytes, "text/plain", Some("Simple data"), Some(EmailAttachment.INLINE)),
        // adds cid attachment
        AttachmentFile("image.jpg", new File("/some/path/image.jpg"), contentId = Some(cid))
      ),
      // sends text, HTML or both...
      bodyText = Some("A text message"),
      bodyHtml = Some(s"""<html><body><p>An <b>html</b> message with cid <img src="cid:$cid"></p></body></html>""")
    )
    mailerClient.send(email)
  }

}

Configuration will be retrieved each time mailerClient.send(email) is called. This means that mailer client will always be up to date if you have a dynamic configuration.

Compile Time Injection

If you use Compile time Injection you can remove libraryDependencies += "org.playframework" %% "play-mailer-guice" % -version- from your build.sbt.

Create the MailerService without the @Inject annotation:

import play.api.libs.mailer._

class MyComponent(mailerClient: MailerClient) {

  def sendEmail = {
     val email = Email("Simple email", "Mister FROM <[email protected]>", Seq("Miss TO <[email protected]>"), bodyText = Some("A text message"))
     mailerClient.send(email)
  }
}

Then you need to register the MailerComponents trait in your main Components file:

import play.api._
import play.api.ApplicationLoader.Context
import router.Routes
import play.api.libs.mailer._

class MyApplicationLoader extends ApplicationLoader {
  def load(context: Context) = {
    new ApplicationComponents(context).application
  }
}

class ApplicationComponents(context: Context) extends BuiltInComponentsFromContext(context) with MailerComponents {
  lazy val myComponent = new MyComponent(mailerClient)
  // create your controllers here ...
  lazy val router = new Routes(...) // inject your controllers here
  lazy val config = configuration.underlying
}

Dynamic Configuration

By default the Mailer Plugin will automatically configure the injected instance with the application.conf.

If you want to configure the injected instances from another source, you will need to override the default provider:

Create a new file named CustomSMTPConfigurationProvider.scala:

class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] {
  override def get() = {
    // Custom configuration
    new SMTPConfiguration("example.org", 1234)
  }
}

class CustomMailerConfigurationModule extends Module {
  def bindings(environment: Environment, configuration: Configuration) = Seq(
    bind[SMTPConfiguration].toProvider[CustomSMTPConfigurationProvider]
  )
}

And override the default provider inside you application.conf:

play.modules {
    # Disable the default provider
    disabled += "play.api.libs.mailer.SMTPConfigurationModule"
    # Enable the custom provider (see above)
    enabled += "controllers.CustomMailerConfigurationModule"
}

The get() method of your CustomSMTPConfigurationProvider will be called multiple times. As a consequence, we recommend that code inside the get() method should be fast.

Multiple SMTPMailer instances

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("example.org", 1234)).send(email)
new SMTPMailer(SMTPConfiguration("playframework.com", 5678)).send(email)

Java

For Java you can just create a simple MailerService and Inject the MailerClient into it:

import play.libs.mailer.Email;
import play.libs.mailer.MailerClient;
import javax.inject.Inject;
import java.io.File;
import org.apache.commons.mail.EmailAttachment;

public class MailerService {
  @Inject MailerClient mailerClient;

  public void sendEmail() {
    String cid = "1234";
    Email email = new Email()
      .setSubject("Simple email")
      .setFrom("Mister FROM <[email protected]>")
      .addTo("Miss TO <[email protected]>")
      // adds attachment
      .addAttachment("attachment.pdf", new File("/some/path/attachment.pdf"))
      // adds inline attachment from byte array
      .addAttachment("data.txt", "data".getBytes(), "text/plain", "Simple data", EmailAttachment.INLINE)
      // adds cid attachment
      .addAttachment("image.jpg", new File("/some/path/image.jpg"), cid)
      // sends text, HTML or both...
      .setBodyText("A text message")
      .setBodyHtml("<html><body><p>An <b>html</b> message with cid <img src=\"cid:" + cid + "\"></p></body></html>");
    mailerClient.send(email);
  }
}

Releasing a new version

See https://github.com/playframework/.github/blob/main/RELEASING.md

License

This software is licensed under the Apache 2 license, quoted below.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

play-mailer's People

Contributors

a1kemist avatar alirussell avatar benmccann avatar c100k avatar dspasojevic avatar dwijnand avatar eirslett avatar ennru avatar freekh avatar ggrossetie avatar gmethvin avatar ignasi35 avatar ihostage avatar jroper avatar laszlovandenhoek avatar loicdescotte avatar marcospereira avatar martinburger avatar mbseid avatar mkurz avatar ndeverge avatar ne-lexa avatar nraychaudhuri avatar octonato avatar ph2734 avatar scala-steward avatar schmitch avatar stephenmuss avatar techmag avatar tsuyoshizawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

play-mailer's Issues

SMTPConfiguration causing Compilation error

package mail

import javax.inject.Provider

import play.api.libs.SMTPConfiguration
import play.api.{Configuration, Environment}
import play.api.inject.Module

class TestMailerConfigurationProvider extends Provider[SMTPConfiguration] {
    override def get() = new SMTPConfiguration("http://192.168.9.2", 25)
}

class TestMailerConfigurationModule extends Module {
    def bindings(environment: Environment, configuration: Configuration) = Seq(
        bind[SMTPConfiguration].toProvider[TestConfigurationProvider]
    )
}

Hi, I'm pretty new to Scala here so pardon me in advance. Above is my implementation of runtime mailer provider override as seen in the samples of this repo. However, this causes a CompilationError due to [object SMTPConfiguration is not a member of package play.api.libs.mailer]

My current version of mailer included in built.sbt is

"com.typesafe.play" %% "play-mailer" % "3.0.1"
Is this class not included in the package as of that version?

Thank you for your help in advance.

Change the documentation format

Currently the documentation format is in Ascii Doc I don't think that is suitable anymore.
I would like to propose a switch to either Markdown or RST

MailPlugin not found in 3.0.0-M1

I checked the contribution guidelines, and I still didnt know whether I should post this on the mailing list or here. But the 3.0.0-M1 is broken and not compatible with play2.4, as (I checked in the code) it does not have the MailPlugin object. Are you able to release a M2 as soon as you get the chance?

Socket timeouts

Hi,

Is it possible to configure the connect and I/O timeouts?

I (think) that I can see that they are not configurable as plugin settings, but I am not sure whether it is possible to configure the underlying javax.mail session directly.

Setting mail.smtp.timeout and mail.smtp.connectiontimeout as system properties has no effect since commons-email's org.apache.commons.mail.Email has a default timeout greater than zero (EmailConstants.SOCKET_TIMEOUT_MS) and that will be used instead (lines 678 -> 687).

If I am not mistaken and the plugin does not currently support configuring those options, do you think that support should be added?

Thanks,
-Dan

play.mailer configuration does not work

I am using play-mailer 3.0.0-RC1 with play 2.4.0 java.

When I start my app I have a warning that tolds me to use the new syntax for configuration

But with this new syntax I have an exception java.lang.RuntimeException: play.mailer.host needs to be set in application.conf in order to use this plugin (or set play.mailer.mock to true)

Configuration that works

smtp {
  host = "mailtrap.io"
  port = 2525
  tls = true
  user = "xxx"
  password = "xxx"
}

Configuration that does not work

play {
  mailer {
    host = "mailtrap.io"
    port = 2525
    tls = true
    user = "xxx"
    password = "xxx"
  }
}

Retrieve the latest configuration before sending an email

Hello, currently we have something like that:

class SMTPMailer @Inject() (smtpConfiguration: SMTPConfiguration) extends MailerClient {

However the Provider doesn't help here since the SMTPMailer will just do the same as before.

Currently it would be great if SMTPMailer stays the same so that we contain compability, however for the injection point it would be better to have something like:

class ConfigurableMailer @Inject()(smtpConfigurationProvider: Provider[SMTPConfiguration]) extends MailerClient {

  override def send(data: Email): String = {
    new SMTPMailer(smtpConfigurationProvider.get()).send(data)
  }

}

If we don't the Provider makes just no sense.

Testing that an email is sent

Is there a way to test that an email is sent, and check the contents of it? Would be nice to do something like:

"A verification email is sent when the user has registered" in {
  MailPlugin.startCapturing()
  UserModule.registerNewUser(name = "Frodo", email = "[email protected]")
  val emails: List[Email] = MailPlugin.stopCapturingAndCollectResults()

  emails mustEqual List(
    Email(
      subject = "Welcome Frodo",
      recipient = "[email protected]",
      bodyText = "Here is your verifcation link: ______"
    )
  )
}

Or perhaps something more "functional"/safe:

"A verification email is sent when the user has registered" in {
  val emails: List[Email] = MailPlugin.captureMailsSentInBlock {
    UserModule.registerNewUser(name = "Frodo", email = "[email protected]")
  }

  emails mustEqual List(
    Email(
      subject = "Welcome Frodo",
      recipient = "[email protected]",
      bodyText = "Here is your verifcation link: ______"
    )
  )
}

Is it possible to do something like this at all right now? ie. Setting the plugin in testing/capture mode so that we can verify: (1) that en email is sent, (2) verify the contents of it.

Also, mock-mode must be on when running your test suite, right? (play.mailer.mock = yes)

I'm sorry if this is asked before, but I couldn't find anything in the manual or from searching.

Adding the user email to the HTML body doing bulk emails

A question: is it possible in a bulk email situation to add the target email to the html?

Google's guidelines suggest that there should be an unsubscribe link which only needs one click for the user to unsubscribe. This means that each email is unique. Currently I add all my recipients to a single message, but I don't see a way of doing this.

I haven't tested the impact of creating 5000+ separate emails, and that might be an option, but I would first like to check if there is a more efficient way.

Test Play App with smtp.mock=true configuration param raises an error

I hav set in my application configuration the param smpt.mock=true and I get the following error by executing the testcae. What should be wrong?

java.lang.RuntimeException: smtp.host needs to be set in application.conf in order to use this plugin (or set smtp.mock to true)

smtp.mock=true
#smtp.host=smtp.gmail.com
#smtp.port=587
#smtp.ssl=true
#smtp.user="xxx"
#smtp.password=xxx
    @Test
    public void testIndexWithTestServerRunnable() {
        running(testServer(3333), new Runnable() {
            @Override
            public void run() {
                assertThat(
                        WS.url("http://localhost:3333").get().get(5000).getStatus()
                ).isEqualTo(OK);
            }
        });
    }

Inject mailerClient in Global.java

In my Global.java I'm trying to schedule a task which has to sent an email every now and then based on some parameters. I can't seem to access mailerClient though, because I always get a NullPointerException. Can someone explain what I'm doing wrong? My code looks roughly like this:

public class Global extends GlobalSettings {
   @Inject MailerClient mailerClient;

   public void onStart(Application app) {
       // lines of code
       Runnable showTime = new Runnable() {
          @Override
          public void run() {
             //lines of code
             mailerClient.send(email);
          }
       }
    }
}

I can't seem to figure out what's going wrong, any help is appreciated.

NoClassDefFoundError org/apache/commons/mail/MultiPartEmail

Hello im working on a play project
and im trying to get this plugin working.

But im getting this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/mail/MultiPartEmail
    at play.api.libs.mailer.CommonsMailerPlugin.mailerInstance$lzycompute(MailerPlugin.scala:531)

https://gist.github.com/hendrik-weiler/8def78a77f2802a69c18

Ive build the plugin from source and add it to the lib folder.
Im running the dist application using this script:
https://github.com/rpgboss/rpgboss-asset-server/blob/master/run-asset-server.sh

The project im working on:
https://github.com/rpgboss/rpgboss-asset-server

Having an issue building the master branch (JDK?)

When trying to compile master I get :

sbt.ResolveException: unresolved dependency: org.json4s#json4s-native_2.10;3.2.10: configuration not found in org.json4s#json4s-native_2.10;3.2.10: 'master(compile)'. Missing configuration: 'compile'. It was required from net.databinder.dispatch#dispatch-json4s-native_2.10;0.11.2 compile

The 2.3.x branch builds find. From what I can tell the only diff between the branches that would cause issues with building is the switch to v8 of the JDK. Which is strange since I'm running Java 8:

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
 $ javac -version
javac 1.8.0_45

Any ideas? I'm probably missing something simple!
Thanks

Instantiation of a MailerClient

I would like to instantiate an instance of a MailerClient outside of a Play controller or component (i.e. without dependency injection) for usage in a Util object, like:

object Util {
val mailerClient = xxxxx
def sendMail(email: Email) {
mailer.send(email)
}

Do I have to use native Guice or how does this work?

Thanks,
Peter

Support Content-Transfer-Encoding or more MimeHeaders

Hello, currently it would be great if we would have more options in specifing Mime Data.

I think the only way to handle that as good as possible would be a more loose mime field which would just append the necessary Bytes.
Like a List[(String, String)] or something which will be appended without validation

Move mailer into its own package

Currently the package of the mailer is com.typesafe.plugins. It should probably be play.libs.mailer for Java and play.api.libs.mailer for Scala.

Publish version 5.0.0.M1 version

This version will be compatible with Play! 2.5 and will make it easier to use dynamic configuration with runtime DI: #81

This version must be released from master branch.

PlayConfig.getOptional has been removed from PlayFramework in Master branch

Hi,

The Play Mailer project is using 2.4.2 right now which should not have any issues, but I just wanted to note that in the Play Framework Master branch things have changed that would cause PlayConfig to break if run against Play Master instead of 2.4.2.
This pull request: playframework/playframework#4588 has removed the getOptional calls that are used by MailerPlugin.scala (See: https://github.com/playframework/play-mailer/blob/35358de784cae2158d12579d0283b10a28dcb0a3/src/main/scala/play/api/libs/mailer/MailerPlugin.scala)

As such, at some point you will probably want to adjust the Play Mailer plugin accoringly.

Thanks,

-Sean

Create a sendAsync method

When I send an email I don't want to "block" my process. I'm using Akka to "schedule" the send:

Akka.system.scheduler.scheduleOnce(1.seconds) {
}

Maybe we can add a sendAsync to the API to do that ? or just an example in the documentation ?
And it might be better to return a Future ?

Release with bugfixes.

Hi. Can you make 2.4.1 or 2.4.1-SNAPSHOT release. I need issues from this commit : 3ae39a8
to be fixed pretty bad.
Thanks

Configuration should be changeable in Code

Hello, currently the configuration of the Mailer is only changeable inside the application.conf,
however that is aweful since sometimes you wan't to make it User Configurable.

Could we add a .editorconfig?

Currently it's always hard to force a certain style to your editor, for that there is a great plugin called editorconfig. Could I support a PR to support that?

How is someone that is not (yet) fully Play/Scala/SBT literate supposed to tell what the actual version number is?

I've tried

sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;2.4.0-RC1: not found
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;2.4.0: not found
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;2.4.1: not found
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;2.4.1-SNAPSHOT: not found
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;3.0.0-M1: not found
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-mailer;{version}: not found 

(just in case this was supposed to be an automatic thingy...)

There must be some "obvious" way to determine exactly what the current version is to the initiated.

Please initiate me :)

I fell in love with Play -- turns out that I'm really starting to hate sbt :(

Provide convenience method for getting a reference to the mailer API

Previously the play-mailer depended on play plugins util for users to conveniently access it. Let's remove this dependency.

Instead create an object that takes an implicit application to get the mailer in Scala, and a plain old static method in Java.

For Play 2.4, we should switch to using the new modules API and expect people to use DI.

Split the MailerPlugin and the MailerPluginSpec into multiple files

Currently the MailerPlugin and the MailerPluginSpec used a single file for their plugin, however that isn't suitable anymore since the project grown and now contains a lot of classes / lines of code in a single file.

To cleanup this plugin we should split the most classes into a single file / group them when they should stick together.

No Support for Compile Time DI with Play 2.4

Hi,
Play 2.4 supports both runtime and compile time dependency injection.
As CommonsMailer uses @Inject it seems impossible to use it without the Guice container.
It would be nice to provide a trait that provide a "raw" mailer client and that could be mixed in Play's BuiltInComponentsFromContext to support compile time DI, like this WS Component for example.

Thanks

Loïc

Play2.4 Field Injection always return null MailerClient

Was following the Java example on home page, use Field injection in Play 2.4. But in debug it seems always have null for MailerClient.

code looks like this:

class EnvelopJob implements Runnable {
        Mail.Envelop envelop;

        @Inject MailerClient mailerClient;

        public EnvelopJob(Mail.Envelop envelop) {
            this.envelop = envelop;
        }

        public void run() {
            Email email = new Email();

            final Configuration root = Configuration.root();
            final String mailFrom = root.getString("mail.from");
            email.setFrom(mailFrom);
            email.setSubject(envelop.subject);
            for (String toEmail : envelop.toEmails) {
                email.addTo(toEmail);
                Logger.debug("Mail.sendMail: Mail will be sent to " + toEmail);
            }

            final String mailSign = root.getString("mail.sign");
            email.setBodyText(envelop.message + "\n\n " + mailSign);
            mailerClient.send(email);
        }
}

Support for cid

I'm trying to generate an email with inline image. Based on my tests, it seems that there is no way to define cid (it's not included in generated mail) for an inline attachment.

Can you please verify?

package play.libs.mailer does not exist

1.- package play.libs.mailer does not exist
2.- package play.libs.mailer.MailerPlugin does not exist

your whole plugin doesn't work :S is there any alternative?

Misleading ReadMe.md

Looks like the Readme.md is misleading. The information doesnot help while testing for Play 2.3.6.

unresolved dependency: javax.activation#activation;1.1.1

It seems that sbt can't resolve the javax.activation transitive dependency.

Using Play! 2.4.x.

In build.sbt:

libraryDependencies ++= Seq(
    // other things...

    "com.typesafe.play" %% "play-mailer" % "3.0.1"
)

When attempting to compile with sbt there is a dependency resolution error:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: javax.activation#activation;1.1.1: configuration not found in javax.activation#activation;1.1.1: 'master(compile)'. Missing configuration: 'compile'. It was required from org.apache.commons#commons-email;1.3.3 compile
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Unresolved dependencies path:
[warn]      javax.activation:activation:1.1.1
[warn]        +- org.apache.commons:commons-email:1.3.3
[warn]        +- com.typesafe.play:play-mailer_2.11:2.4.1 (/Users/pete/projects/issuance/build.sbt#L14-31)
[warn]        +- issuance:issuance_2.11:1.0-SNAPSHOT
...
sbt.ResolveException: unresolved dependency: javax.activation#activation;1.1.1: configuration not found in javax.activation#activation;1.1.1: 'master(compile)'. Missing configuration: 'compile'. It was required from org.apache.commons#commons-email;1.3.3 compile

"Could not find a suitable constructor in com.typesafe.plugin.CommonsMailerPlugin" on play-2.4.0-M2

Trying to friend play-2.4 with play-mailer plugin, but:

[error] application - 

! @6keh7m8ll - Internal server error, for (GET) [/] ->

play.api.UnexpectedException: Unexpected exception[ConfigurationException: Guice configuration errors:

1) Could not find a suitable constructor in com.typesafe.plugin.CommonsMailerPlugin. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at com.typesafe.plugin.CommonsMailerPlugin.class(MailerPlugin.scala:490)
  while locating com.typesafe.plugin.CommonsMailerPlugin

1 error]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:176) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.11.4.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]
Caused by: com.google.inject.ConfigurationException: Guice configuration errors:

1) Could not find a suitable constructor in com.typesafe.plugin.CommonsMailerPlugin. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at com.typesafe.plugin.CommonsMailerPlugin.class(MailerPlugin.scala:490)
  while locating com.typesafe.plugin.CommonsMailerPlugin

1 error
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004) ~[guice-3.0.jar:na]
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961) ~[guice-3.0.jar:na]
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013) ~[guice-3.0.jar:na]
    at play.api.inject.guice.GuiceInjector.instanceOf(GuiceApplicationLoader.scala:140) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]
    at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:89) ~[play_2.11-2.4.0-M2.jar:2.4.0-M2]

Move to new configuration structure

We've migrated all of the Play config to provide all defaults in reference.conf, even optional values, these get a default of null, and documenting everything in there. play-mailer should do this too. Additionally, we've namespaced everything in play. I think the mailer should use the namespace of play.mailer.

Whoever implements this, take a look at play.api.PlayConfig, this can be used to "deprecate" the old config, so we can say:

val mailerConfig = PlayConfig(configuration).getDeprecated[PlayConfig]("play.mailer", "smtp")

That way, the user gets a deprecation warning if they have anything configured at smtp.

Next release

Hi All,

The "configure" method is a real plus.
Please do you know when the change will be released ?

Regards,

PYC

object mailer is not a member of package play.api.libs

There is an issue with using "com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.1"
as described here [https://github.com/playframework/play-mailer/blob/master/README.md].

Take a look at contents of [http://repo.typesafe.com/typesafe/releases/com/typesafe/play/plugins/play-plugins-mailer_2.11/2.3.1/play-plugins-mailer_2.11-2.3.1.jar]

[09:05:29] skierat ~/Downloads jar tvf play-plugins-mailer_2.11-2.3.1.jar 
   323 Fri Oct 24 08:39:06 CEST 2014 META-INF/MANIFEST.MF
     0 Fri Oct 24 08:39:06 CEST 2014 com/
     0 Fri Oct 24 08:39:06 CEST 2014 com/typesafe/
     0 Fri Oct 24 08:39:06 CEST 2014 com/typesafe/plugin/
   507 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerPlugin.class
  3228 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$Attachment$.class
  1092 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$19.class
  2163 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8$$anonfun$apply$6.class
  1668 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$9.class
  6268 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder.class
  5403 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer.class
  1581 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$4.class
  1186 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerAPI.class
  1009 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$3.class
  1316 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$12.class
  1318 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$17.class
  1319 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$13.class
  1522 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$18.class
   927 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$1.class
  1054 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8$$anonfun$7.class
  1238 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$14$$anonfun$apply$13.class
  1618 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$9$$anonfun$apply$9.class
  1319 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$11.class
  4893 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin.class
  1581 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$6.class
   846 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$10.class
  5187 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$Attachment.class
  1314 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$14.class
  1514 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$7.class
  1269 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$$anon$3.class
  2279 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8$$anonfun$apply$6$$anonfun$apply$7.class
  1025 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anon$1$$anonfun$write$1.class
  1136 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$8.class
  1703 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$$anonfun$e$2.class
 13241 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer.class
  1315 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$16.class
  1240 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$16$$anonfun$apply$15.class
  2220 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8$$anonfun$apply$8.class
   922 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$5.class
  1581 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$3.class
  1562 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$5$$anonfun$apply$4.class
  1136 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$$anonfun$e$3.class
  1248 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$13$$anonfun$apply$12.class
  1246 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$17$$anonfun$apply$16.class
  1563 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$6$$anonfun$apply$5.class
  1124 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anon$1$$anonfun$write$2.class
  1581 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$2.class
  1305 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8$$anonfun$6.class
  9495 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$class.class
  1297 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$enabled$1.class
  1567 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$3$$anonfun$apply$2.class
  1448 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$18$$anonfun$apply$17.class
  1263 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$$anon$2.class
   944 Fri Oct 24 08:39:06 CEST 2014 com/typesafe/plugin/MailerApiJavaInterop.class
  1612 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MailerBuilder$$anonfun$e$1.class
 10429 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$.class
  1317 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anon$1.class
  1242 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$12$$anonfun$apply$11.class
  2588 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$8.class
  1009 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$2.class
  1314 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$15.class
  1564 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$2$$anonfun$apply$1.class
  1248 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$11$$anonfun$apply$10.class
  1009 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$4.class
  1562 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$4$$anonfun$apply$3.class
  1581 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailer$$anonfun$send$5.class
   973 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$mock$1.class
  1092 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$20.class
  1010 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/CommonsMailerPlugin$$anonfun$1.class
  1238 Fri Oct 24 08:39:04 CEST 2014 com/typesafe/plugin/MockMailer$$anonfun$send$15$$anonfun$apply$14.class

There isn't a package play.api.libs

I found a related problem on [http://stackoverflow.com/questions/27130048/how-to-use-play-plugins-mailer-with-play-2-3-and-scala-2-11]

I don't want to build from sources, so could you please fix and release a correct version?

What package should the MailerPlugin be located in?

The sample application included fails to compile because it's looking for MailerPlugin inside play.api.libs.mailer. On inspection of the latest 2.3.1 release, it appears to still be located within the com.typesafe.plugin namespace.

The namespace changes on github don't appear to be reflected in the published jar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.