Grails:从邮件发送或不发送的mailService返回

时间:2017-04-04 06:47:30

标签: java grails

这是我最近使用的代码

if(!toAddress.equalsIgnoreCase("")){
            mailService.sendMail {
                to toAddress
                subject "This is a test mail"
                body "Hello, This is a test mail."
            }
}

但我不知道如何从sendMail获取返回结果

1 个答案:

答案 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) 
}
相关问题