6
回答
grails关于 mail出现错误
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

config.groovy

 

grails {
   mail {
     host = "smtp.qq.com"
     port = 465
     username = *******@qq.com
     password = "**********"
     props = ["mail.smtp.auth":"true",
              "mail.smtp.socketFactory.port":"465",
              "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
              "mail.smtp.socketFactory.fallback":"false"]   }
}

 

MailController

 

package mail
import org.grails.mail.MailService

class MailController {

  def  mailService

  def mailNotice = {
    println("------------------")
 
   mailService.sendMail {
   to "***********@qq.com"
 
   subject "Hello John"
   body 'this is some text'
}

  }


}
页面测试是一个 链接 <a href="mailNotice">dd</a>

 

报错 是2010-11-12 12:57:10,718 [http-8080-3] ERROR errors.GrailsExceptionResolver  - null
javax.mail.AuthenticationFailedException
 at javax.mail.Service.connect(Service.java:319)
 at org.grails.mail.MailService.sendMail(MailService.groovy:63)
 at org.grails.mail.MailService.sendMail(MailService.groovy:46)
 at org.grails.mail.MailService$sendMail.call(Unknown Source)
 at mail.MailController$_closure1.doCall(mail.MailController:11)
 at mail.MailController$_closure1.doCall(mail.MailController)
 at java.lang.Thread.run(Thread.java:619)

请教高手 这个是什么错误

举报
join
发帖于7年前 6回/535阅
共有6个答案 最后回答: 7年前

引用来自#3楼“join”的帖子

用户名 和密码 真没错  我QQ还等着呢

javax.mail.AuthenticationFailedException

你还得确定,你的qq邮箱允不允许。

不行的话,就在spring/resources.groovy里这么配:

mailSender(org.springframework.mail.javamail.JavaMailSenderImpl) {
        host = "smtp.126.com"
                javaMailProperties = ["mail.smtp.auth":true,"mail.smtp.timeout":25000]
                username = "xxxx"
                password = "xxxx"
    }

在controller中注入:

def mailSender

def sendMail = {

def mail= new SimpleMailMessage()
                            mail.to = 'xxxx'
                            mail.from = 'xxxx@126.com'
                            mail.subject = 'lxxx'
                            mail.text = '光棍节快乐'
                            mailSender.send(mail);

}

顶部