gpt4 book ai didi

java - Grails:从是否发送邮件的mailService获得返回

转载 作者:行者123 更新时间:2023-12-02 15:48:34 26 4
gpt4 key购买 nike

这是我最近使用的代码

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

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

最佳答案

我在插件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)
}

关于java - Grails:从是否发送邮件的mailService获得返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43200136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com