7

I am continuously receiving following error message while trying to configure grails mail plugin (https://grails.org/plugin/mail) for grails spring security plugin.

Here is my configuration looks so far,


    grails {
        mail {
            host = "smtp.office365.com"
            port = 587
            username = "info@email.com"
            password = "password"
            props = ["mail.smtp.starttls.enable":"true",
                     "mail.smtp.port":"587"]
        }
    }

    grails.mail.default.from = "info@email.com"

And here is my stack-trace.


    .......| Error 2015-04-17 11:59:39,184 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - MailSendException occurred when processing request: [POST] /retouch/register/forgotPassword - parameters:
    username: customer
    Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.60 SMTP; Client does not have permissions to send as this sender
    . Stacktrace follows:
    Message: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.60 SMTP; Client does not have permissions to send as this sender
        Line | Method
    ->>  131 | sendMessage    in grails.plugin.mail.MailMessageBuilder
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |     55 | sendMail       in grails.plugin.mail.MailService
    |     59 | sendMail . . . in     ''
    |    156 | forgotPassword in grails.plugin.springsecurity.ui.RegisterController
    |    198 | doFilter . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
    |     63 | doFilter       in grails.plugin.cache.web.filter.AbstractFilter
    |     53 | doFilter . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
    |     49 | doFilter       in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
    |     82 | doFilter . . . in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
    |   1145 | runWorker      in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    745 | run            in java.lang.Thread

Note: Problem is only find in Grails spring security plugin.

Balkrishna
  • 2,897
  • 3
  • 23
  • 31

3 Answers3

8

I ran into the exact same issue. Problem seems to arise due to spring security trying to set "from" attribute in the email as no-reply@localhost. Try adding these lines to the config file

 grails.plugin.springsecurity.ui.register.emailFrom = 'info@email.com'
 grails.plugin.springsecurity.ui.forgotPassword.emailFrom = 'info@email.com'

note: info@email.com is your office365 email

Aasiz
  • 647
  • 8
  • 18
  • 1
    you should also add grails.plugin.springsecurity.ui.forgotPassword.emailFrom = 'info@email.com' line – Aasiz Apr 17 '15 at 16:22
  • I did not need the above 2 lines re "springsecurity". I only was missing the "grails.mail.default.from" part to access office365.com. (Note this was not needed using a GMail sender account) – Alan Thompson May 05 '15 at 22:26
4

username = "info@emal.com"

grails.mail.default.from = "info@email.com"

username email must equal to from email.

hahamy
  • 81
  • 3
  • Sorry this is not the case. I know both email should be same. Here is just a typo while changing original email. – Balkrishna Apr 17 '15 at 07:08
4

I got Grails sending email pretty easily using a test GMail account, but the code crashed with the error when I tried to send from an outlook.office365.com account:

Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.60 SMTP; Client does not have permissions to send as this sender

It turns out I was only missing this line:

grails.mail.default.from = "sample@somewhere.com"

Note the the email address specified in grails.mail.default.from must match the one in grails.mail.username .

Here is the configuration that worked for me. Base example is the Hubbub example from the book Grails in Action (2nd Ed):

grails.mail.default.from = "sample@somewhere.com"
grails {
  mail {  
      host = "outlook.office365.com"
      port = 587
      username = "sample@somewhere.com"
      password = "secret"
      props = [ "mail.smtp.starttls.enable" : "true",
                "mail.smtp.port"            : "587",
                "mail.smtp.debug"           : "true" ]
  }

and here is the corresponding email sending function:

def email() {
  println( "Sending email.." );
  sendMail {
      to "test@gmail.com"
      subject "[mail-test]"
      body ("This is a test email, time: " + new Date() )
  }
  println( "  success!!!" );
  flash.message = "Successfully sent email"
  redirect( uri: "/" );
}
Alan Thompson
  • 29,276
  • 6
  • 41
  • 48