Email verification in grails
Asked Answered
R

1

7

I am new with grails and am developing a web application in grails.

In my registration page I am getting the user's email id and I need to send a mail with authentication link.

http://grails.org/plugin/mail

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

I have referred these pages and many other pages to do this task. But the problem is, my email is not sending.

I have used

Gmail SMTP server address : smtp.gmail.com
Gmail SMTP username : [email protected]
Gmail SMTP password : -my password-
Gmail SMTP port : 465
Gmail SMTP TLS/SSL required : yes

Mail settings are:

grails { 
    mail { 
        host = "smtp.gmail.com" 
        port = 465 
        username = "[email protected]" 
        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="[email protected]"

but at least

sendMail {     
  to "[email protected]"     
  subject "Hello "     
  body 'How are you?' 
}

is not working.

The exception occured is

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);

this is the exception

Remarque answered 12/3, 2014 at 5:9 Comment(6)
Paste your mail settings from config.groovy. Are you getting any errors ? What happens, do you see any thing on console !Dunsinane
grails { mail { host = "smtp.gmail.com" port = 465 username = "[email protected]" 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="[email protected]" the view page is not changing.Remarque
can you login into Gmail with those credentials? Gmail often refuses connections the first time from an unknown client. Look for email notifications for this in your inbox. also check support.google.com/mail/answer/14257?p=client_login&rd=1Ruyle
I have tried all these.... But still the same error.Remarque
as the trace suggests ssl is used and so your config is most likely picked up. can you test connecting? e.g. telnet smtp.gmail.com 465?Automatic
bash: telnet: command not found is the outputRemarque
S
6

Try this it's worked for me. Notice that: Gmail SMTP TLS/SSL required : yes. But you don't put "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"]
Storage answered 13/3, 2014 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.