创建了一个简单的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
中有什么变化?
答案 0 :(得分:6)
Build.scala
并且瞧!它汇编了。
val commonsMail = "org.apache.commons" % "commons-email" % "1.3"