我正在尝试用grails调用发送邮件。我是从控制器打来的
class TournamentController {
static scaffold = true
//controller functions
def emailParticipants(Tournament t) {
def emailSubject = "Tournament ${t.title} complete"
for (Prediction p : t.predictions){
if (p.email != null){
def emailBody = """\
Hello ${p.name}! Thank you for participating in the ${t.title} tournament.
Please find a link below with statistics and match results.
"""
sendMail {
async true
to p.email
subject emailSubject
body emailBody
}
}
}
}
}
我得到的错误是一个MissingMethodException,其中包含以下消息:
No signature of method: predictionpal.MailService.sendMail() is applicable for
argument types(predictionpal.TournamentController$_emailParticipants_closure2)
values
[predictionpal.TournamentController$_emailParticipants_closure2@51fc1bbb]
Possible solutions: findAll()
以下是我添加到BuildConfig.groovy
的内容grails.project.dependency.resolution = {
//There is a stuff I didn't add here
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// **I ONLY ADDED THIS LINE**
compile ":mail:1.0.7"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"
// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.18" // or ":hibernate4:4.3.6.1"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
runtime ":console:1.5.3"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
我尝试过做
grails stop-app
grails clean
grails run-app
但我的问题仍然没有解决。
答案 0 :(得分:1)
您必须在控制器类中使用mailService
bean:
class TournamentController {
static scaffold = true
def mailService // Inject the bean
def emailParticipants(Tournament t) {
def emailSubject = "Tournament ${t.title} complete"
for (Prediction p : t.predictions){
if (p.email != null){
def emailBody = """\
Hello ${p.name}! Thank you for participating in the ${t.title} tournament.
Please find a link below with statistics and match results.
"""
mailService.sendMail { // Use the bean's sendMail method
async true
to p.email
subject emailSubject
body emailBody
}