无法在 Grails 应用程序中调用 sendMail 函数
Unable to call sendMail function in grails application
我正在尝试在 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
但我的问题仍未解决。
您必须在控制器中使用 mailService
bean class:
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
}
我正在尝试在 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
但我的问题仍未解决。
您必须在控制器中使用 mailService
bean class:
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
}