3
創建一個簡單的Apache Commons Email對象並去編譯它。進口:import org.apache.commons.mail._
和javax.mail.internet.MimeMessage
,也做了以下內容:Apache Mailer在Scala中拋出編譯器錯誤?
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 <[email protected]>")
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
中更改了某些內容?
修復你的類路徑。它沒有找到導入的java類。 – 2013-02-28 00:00:30
你指的是'javax'嗎?這不是標準Java 6的一部分嗎? – crockpotveggies 2013-02-28 00:31:01