3

创建了一个简单的 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

4

1 回答 1

6

Mel Nicholson 指出了正确的问题,它与未获取的依赖项有关。我没有意识到我下载的 Apache JAR 没有附带它。因此,我只是将其添加到我的 sbt 中Build.scala,瞧!它编译。

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

于 2013-02-28T00:59:17.877 回答