【问题标题】:Email verification in grailsGrails 中的电子邮件验证
【发布时间】:2014-04-16 01:18:42
【问题描述】:

我是 grails 新手,正在使用 grails 开发一个 Web 应用程序。

在我的注册页面中,我正在获取用户的电子邮件 ID,我需要发送一封带有身份验证链接的邮件。

http://grails.org/plugin/mail

http://grails.org/plugin/email-confirmation

我已经参考了这些页面和许多其他页面来完成这项任务。 但问题是,我的电子邮件没有发送。

我用过

Gmail SMTP server address : smtp.gmail.com
Gmail SMTP username : myid@gmail.com
Gmail SMTP password : -my password-
Gmail SMTP port : 465
Gmail SMTP TLS/SSL required : yes

邮件设置为:

grails { 
    mail { 
        host = "smtp.gmail.com" 
        port = 465 
        username = "myId@gmail.com" 
        password = "mypassword" 
        props = [
            "mail.smtp.auth":"true", 
            "mail.smtp.socketFactory.port":"465", 
            "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
            "mail.smtp.socketFactory.fallback":"false"] 
    } 
} 
grails.mail.default.from="noreply@gmail.com"

但至少

sendMail {     
  to "friend@gmail.com"     
  subject "Hello "     
  body 'How are you?' 
}

不工作。

发生的异常是

Error 500: Internal Server Error

URI
    /MailVerificationDemo/user/signup/form
Class
    java.net.ConnectException
Message
    Connection refused

Around line 104 of MailMessageBuilder.groovy

101:            log.trace("Sending mail ${getDescription(message)}} ...")102:        }103:104:        mailSender.send(message instanceof MimeMailMessage ? message.mimeMessage : message)105:106:        if (log.traceEnabled) {107:            log.trace("Sent mail ${getDescription(message)}} ...")

Around line 41 of grails-app/services/grails/plugin/mail/MailService.groovy

38:        callable.resolveStrategy = Closure.DELEGATE_FIRST39:        callable.call()40:41:        messageBuilder.sendMessage()42:    }43:44:    def getMailConfig() {

Around line 18 of grails-app/controllers/user/UserController.groovy

15:            return16:        }17:18:        mailService.sendMail {19:            to userInstance.email20:            subject "New User Confirmation"21:            html g.render(template:"mailtemplate",model:[code:userInstance.confirmCode])

Around line 195 of PageFragmentCachingFilter.java

192:            if (CollectionUtils.isEmpty(cacheOperations)) {193:             log.debug("No cacheable annotation found for {}:{} {}",194:                     new Object[] { request.getMethod(), request.getRequestURI(), getContext() });195:               chain.doFilter(request, response);196:              return;197:         }198:

Around line 63 of AbstractFilter.java

60:     try {61:            // NO_FILTER set for RequestDispatcher forwards to avoid double gzipping62:         if (filterNotDisabled(request)) {63:                doFilter(request, response, chain);64:          }65:            else {66:               chain.doFilter(req, res);

【问题讨论】:

  • 从 config.groovy 粘贴您的邮件设置。你有任何错误吗?发生了什么,你在控制台上看到什么了吗!
  • grails { 邮件 { 主机 = "smtp.gmail.com" 端口 = 465 用户名 = "myId@gmail.com" 密码 = "mypassword" 道具 = ["mail.smtp.auth":"真”,“mail.smtp.socketFactory.port”:“465”,“mail.smtp.socketFactory.class”:“javax.net.ssl.SSLSocketFactory”,“mail.smtp.socketFactory.fallback”:“假” ] } } grails.mail.default.from="noreply@gmail.com" 视图页面没有改变。
  • 您可以使用这些凭据登录Gmail 吗? Gmail 第一次经常拒绝来自未知客户端的连接。在您的收件箱中查找与此相关的电子邮件通知。还要检查support.google.com/mail/answer/14257?p=client_login&rd=1
  • 我已经尝试了所有这些......但仍然是同样的错误。
  • 因为跟踪表明使用了 ssl,因此您的配置很可能被拾取。你能测试连接吗?例如telnet smtp.gmail.com 465?

标签: grails grails-2.0 grails-plugin


【解决方案1】:

试试这个它对我有用。 请注意:Gmail SMTP TLS/SSL required : yes. 但是你不要放"mail.smtp.starttls.enable": "true"

grails.mail.host="smtp.gmail.com"
grails.mail.port=587
grails.mail.username="yourUsernameHere"
grails.mail.password="yourPwdHere"
grails.mail.from="defaultMailFromHere"
grails.mail.props = ['mail.smtp.auth': "true",
        "mail.smtp.starttls.enable": "true",
        "mail.from":"defaultMailFromHere"]
grails.mail.javaMailProperties = ['mail.smtp.auth': "true",
        "mail.smtp.starttls.enable": "true",
        "mail.from":"defaultMailFromHere"]

【讨论】:

    猜你喜欢
    • 2012-09-10
    • 2015-11-06
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2018-10-06
    相关资源
    最近更新 更多