尝试通过Gmail发送电子邮件时出现此错误。这是代码,在config.groovy文件中。
mail.MailMessageBuilder Failed to send email
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 ca4sm3178528pbd.79 - gsmtp
at grails.plugin.mail.MailMessageBuilder$_sendMessage_closure1.doCall(MailMessageBuilder.groovy:112)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 ca4sm3178528pbd.79 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:843)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:765)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:687)
at javax.mail.Service.connect(Service.java:345)
... 4 more
CODE:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "yomama@gmail.com"
password = "TTYUIoiuy78"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
我从提供的链接尝试了建议的解决方案。
我已登录并更改了密码。
我解锁了验证码DisplayUnlockCaptcha
我也点击了allow less secure apps access the app
答案 0 :(得分:-1)
我按照这些步骤操作,我没有收到任何错误并且工作正常......
使用命令
安装grails的邮件插件grails install-plugin mail 1.0.7
打开Config.groovy并附加这些行
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "your gmail id"
password = "your password"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
在您要发送邮件的操作中,请使用此代码
sendMail {
to "recepient address"
subject "Hello Fred"
body 'How are you?'
}
使用
编译您的应用grails compile
运行应用