title: Play Framework 2.2.0 Java Email
body: <p>I'm using the Play Framework 2.2.0 with java 7.4.</p>
  
  <p>I've been trying all week to find an email module or package that I can use to send an email from my play application.  I have tried many different packages and each time I get either a package not found exception, a compilation error or package not found exception.</p>
  
  <p>I have had many variations of the <strong>Build.scala</strong>, and the <strong>Build.sbt</strong>.  I also tried unmanaged dependencies and managed dependencies pulling from 'maven' I believe it's called and pulling from my /lib directory respectively.  The packages I have downloaded to my /lib directory are:</p>
  
  <p><strong>commons-io-2.3</strong></p>
  
  <p><strong>javax.mail</strong></p>
  
  <p><strong>play-plugins-mailer_2.2.0</strong></p>
  
  <p>My versions of my <strong>Build.scala</strong> have been:</p>
  
  <p><strong>Build.scala</strong></p>
  
  <p><strong>1st attempt</strong>:</p>
  
  <pre><code>import sbt._
  import Keys._
  
  object ApplicationBuild extends Build {
  
      val appName         = "Asset Manager"
      val appVersion      = "1.0"
  
      val appDependencies = Seq(
          "mysql" % "mysql-connector-java" % "5.1.27",
          "org.scala-tools" %% "scala-stm" % "0.3",
          "org.apache.derby" % "derby" % "10.4.1.3" % "test",
          "org.apache.commons" % "commons-email" % "1.3.1",
          "commons-io" % "commons-io" % "2.3"
      )
  }
  </code></pre>
  
  <p><strong>2nd attempt:</strong></p>
  
  <pre><code>import sbt._
  import Keys._
  
  object ApplicationBuild extends Build {
  
      lazy val buildVersion = "2.2.0"
      lazy val playVersion = "2.2.0"
  
      val appName         = "Asset Manager"
      val appVersion      = "1.0"
  
      val appDependencies = Seq(
          "mysql" % "mysql-connector-java" % "5.1.27",
          "org.scala-tools" %% "scala-stm" % "0.3",
          "org.apache.derby" % "derby" % "10.4.1.3" % "test",
          "commons-io" % "commons-io" % "2.3"
      )
  
      libraryDependencies += "org.apache.commons" % "commons-email" % "1.3.1";
      libraryDependencies += "com.typesafe" %% "play-plugins-util" % buildVersion;
  
  }
  </code></pre>
  
  <p>My Emailing Java File <strong>Parts.java:</strong></p>
  
  <p><strong>1st attempt</strong></p>
  
  <pre><code>package controllers;
  
  import play.libs.*;
  
  import java.io.*;
  import java.util.*;
  
  import org.apache.commons.mail.*;
  
  ...
  
          SimpleEmail email = new SimpleEmail();
          email.setFrom(User.getByUsername(Session.get("username")).email);
          email.addTo(app.configuration().getString("ownerEmail"));
          email.addTo(part.email);
          email.setSubject("Part Added: " + part.vendor + " - " + part.label);
          email.setMsg("A Part has been added to the Asset Manager:\n\n"
              + part.toString());
          Mail.send(email);
  
  ...
  </code></pre>
  
  <p><strong>2nd attempt:</strong></p>
  
  <pre><code>package controllers;
  
  import play.libs.*;
  
  import java.io.*;
  import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import javax.activation.*;
  
  import com.typesafe.plugin._;
  
  ...
  
              MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
              mail.setSubject("test");
              mail.addRecipient("");
              mail.addFrom("");
              mail.sendHtml("A Part has been added to the Asset Manager:\n\n" + part.toString());
  
  ...
  </code></pre>
  
  <p><strong>3rd attempt:</strong></p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  import java.util.*;
  import javax.mail.internet.*;
  import javax.activation.*;
  
  ...
  
              String to = "...";
              String from = "...";
              String host = "localhost";
              Properties properties = System.getProperties();
              properties.setProperty("mail.smtp.host", host);
  
              // Get the default Session object.
              Session session = Session.getDefaultInstance(properties);
  
              try{
                  MimeMessage message = new MimeMessage(session);
                  message.setFrom(new InternetAddress(from));
                  message.addRecipient(Message.RecipientType.TO,
                                    new InternetAddress(to));
                  message.setSubject("This is the Subject Line!");
                  message.setText("This is actual message");
  
                  // Send message
                  Transport.send(message);
                  System.out.println("Sent message successfully....");
              }catch (MessagingException me) {
                  me.printStackTrace();
              }
  ...
  </code></pre>
  
  <p>My question is how do I set up my Play Framework so that it doesn't tell me this:</p>
  
  <pre><code>**Compilation error**
  
  error: cannot find symbol
  In ..\app\controllers\Parts.java at line 116.
  
  113            // mail.addFrom("");
  114            // mail.sendHtml("A Part has been added to the Asset Manager:\n\n" + part.toString());
  115
  116            SimpleEmail email = new SimpleEmail();
  117            email.setHostName("smtp.googlemail.com");
  118            email.setSmtpPort(465);
  119            email.setFrom("","");
  120            // email.setFrom(User.getByUsername(Session.get("username")).email);
  121            email.addTo("");
  </code></pre>
  
  <p>**note: I emptied out some strings that contained personal information.</p>
  
  <p>Whenever I try to refresh my page.  I need to know where I put my package specific information, how the build.scala should look, whether the command order (../play clean; ../play dependencies; ../play run) is correct, whether I should be using managed or unmanaged and ultimately whether or not this is even possible!?!?</p>
  
  <p><strong>Thanks all.</strong></p>