客户端没有作为此发件人发送的权限(office 365,grails)

Client does not have permissions to send as this sender (office 365, grails)

我在尝试为 grails spring 安全插件配置 grails 邮件插件 (https://grails.org/plugin/mail) 时不断收到以下错误消息。

这是我目前的配置,


    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"

这是我的堆栈跟踪。


    .......| 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

注意:问题仅在 Grails spring 安全插件中找到。

用户名 = "info@emal.com"

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

用户名电子邮件必须等于来自电子邮件。

我 运行 遇到了完全相同的问题。问题似乎是由于 spring 安全部门试图将电子邮件中的 "from" 属性设置为 no-reply@localhost。 尝试将这些行添加到配置文件

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

注意:info@email.com 是您的 office365 邮箱

我使用测试 GMail 帐户很容易地使用 Grails 发送电子邮件,但是当我尝试从 outlook 发送时代码因错误而崩溃。office365.com 帐户:

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

原来我只是漏掉了这一行:

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

请注意 grails.mail.default.from 中指定的电子邮件地址必须与 grails.mail.username 中指定的电子邮件地址匹配。

这是适合我的配置。基本示例是 Grails in Action(第 2 版)一书中的 Hubbub 示例:

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" ]
  }

这里是对应的邮件发送函数:

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: "/" );
}