Grails:从bootstrap发送邮件

时间:2013-12-18 19:44:57

标签: grails

我想在服务器重启时发送邮件, 这是我的引导程序:

class BootStrap {
def mailService
def init = { servletContext ->
            // if its dev environment, send mail
    if(Environment.current.getName()=="development") {
        mailService.sendMail{
            to "xxx@gmail.com"
            from "admin@yyy.com"
            subject "Note: Server started at "+new Date();
            html "from yyy app";
        }
    }
}
def destroy = {

}
}

我得到了这个例外:

Error initializing the application: No such property: Environment for class: BootStrap
groovy.lang.MissingPropertyException: No such property: Environment for class: BootStrap
at BootStrap$_closure1.doCall(BootStrap.groovy:5)
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
at grails.util.Environment.executeForEnvironment(Environment.java:301)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
| Error Forked Grails VM exited with error

我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

你需要

import grails.util.Environment