这是我最近使用的代码
if(!toAddress.equalsIgnoreCase("")){
mailService.sendMail {
to toAddress
subject "This is a test mail"
body "Hello, This is a test mail."
}
}
但我不知道如何从sendMail获取返回结果
答案 0 :(得分:0)
我在插件tests中看到,如果某些内容失败,该方法会抛出GrailsMailException。 所以你可以使用try-catch:
try {
mailService.sendMail {
to toAddress
subject "This is a test mail"
body "Hello, This is a test mail."
}
} catch(GrailsMailException e) {
log.warn('Message failed with exception', e)
}