2013-02-27 61 views
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中更改了某些內容?

+0

修復你的類路徑。它沒有找到導入的java類。 – 2013-02-28 00:00:30

+0

你指的是'javax'嗎?這不是標準Java 6的一部分嗎? – crockpotveggies 2013-02-28 00:31:01

回答

5

梅爾尼科爾森指出了正確的問題,它涉及到一個依賴不被提取。我沒有意識到它沒有與我下載的Apache JAR一起提供。所以相反,我只是將它添加到我的sdt Build.scala瞧!它編譯。

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