Apache Mailer在Scala中抛出编译器错误?

时间:2013-02-27 23:56:36

标签: java scala apache-commons

创建了一个简单的Apache Commons Email对象并进行编译。导入:import org.apache.commons.mail._javax.mail.internet.MimeMessage并执行以下操作:

  def sendVerification(user: User) = {
    val email = new SimpleEmail()
        email.setHostName("smtp.sendgrid.net")
        email.setSmtpPort(465)
        email.setAuthenticator(new DefaultAuthenticator("user", "pass"))
        email.setSSLOnConnect(true)
        email.setFrom("Community Admin <admin@domain.com>")
        email.setSubject("TestMail")
        email.setMsg("""Welcome %s!

        Thanks for signing up. This email is to confirm your email address.

        Cheers,
        Admin Team
        """ format user.firstName)
        email.addTo(user.email)
        email.send()
  }

错误如下:

[error] C:\Users\path\to\AccountService\models\User.scala:43: object mail is not a member of package javax
[error] import javax.mail.internet.MimeMessage
[error]              ^
[error] error while loading Email, Missing dependency 'class javax.mail.internet.MimeMessage', required by C:\Users\path\lib\commons-email-1.2.jar(org/apache/commons/mail/Email.class)
[error] C:\Users\path\com\threetierlogic\AccountService\models\User.scala:256: value setHostName is not a member of org.apache.commons.mail.SimpleEmail
[error]                 email.setHostName("smtp.sendgrid.net")

然而,当我去编译时,它会在val email上调用的每个方法上抛出错误。这是一个与可变性有关的问题吗?或者版本1.3中有什么变化?

1 个答案:

答案 0 :(得分:6)

梅尔尼科尔森正指向正确的问题,这与依赖没有被提取有关。我没有意识到它没有附带我下载的Apache JAR。所以我只是将它添加到我的sbt Build.scala并且瞧!它汇编了。

val commonsMail = "org.apache.commons" % "commons-email" % "1.3"