【问题标题】:Rails actionmailer, gmail works, office 365 does not.Rails actionmailer,gmail 可以,office 365 不行。
【发布时间】:2014-10-01 22:07:41
【问题描述】:

我有 Actionmailer 使用 gmail 发送电子邮件,设置如下:

ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "gmail.com",
   :user_name => "user_name@gmail.com",
   :password => "password",
   :authentication => "plain",
   :enable_starttls_auto => true
}

但是,我无法让 Office 365 邮件正常工作,我有以下设置:

ActionMailer::Base.smtp_settings = {
    :address => "smtp.office365.com",
    :port => 587,
    :domain => "my_domain.com",
    :user_name => "username@my_domain.onmicrosoft.com",
    :password => "password",
    :authentication => :login, 
    :enable_starttls_auto => true
}

如果我尝试向该客户发送电子邮件,我会收到:

Net::SMTPFatalError
550 5.7.1 Client does not have permissions to send as this sender

【问题讨论】:

  • 您好,您的问题解决了吗?我有同样的问题。谢谢!
  • 嗨,我发现这是一个内部 IT 问题,我的代码没有任何问题 - 他们只是没有正确设置权限。

标签: ruby-on-rails actionmailer office365


【解决方案1】:

原来微软要求smtp_settingsemailer.rb 中的:from 字段使用相同的电子邮件。

【讨论】:

  • 以上答案有参考吗?
  • 我更改了 app/mailers/application_mailer.rb 中的 from,然后就成功了。和往常一样,永远不要忘记在测试时重置 Rails 服务器!
【解决方案2】:

我在使用 Gmail 和 Office365 时遇到了同样的问题,在摸索了好几个小时后,我找到了解决方案。

如果您使用 Office365 帐户发送电子邮件,则仅当 user_namesender_address 值相同时才有效。即

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.office365.com',
    port:                 587,
    domain:               'my_domain.pk',
    user_name:            'noreply@my_domain.pk',
    password:             ENV['PASSWORD'],
    authentication:       'login',
    enable_starttls_auto: true
  }

  config.middleware.use ExceptionNotification::Rack,
  email: {
    deliver_with:         :deliver,
    email_prefix:         '[Email Prefix]',
    sender_address:       %{<noreply@my_domain.pk>},
    exception_recipients: %w{abc@gmail.com}
  }

config.action_mailer.perform_deliveries = true

关键点:所以保持以下价值观对我有用

user_name: 'noreply@my_domain.pk' 

sender_address: %{<noreply@my_domain.pk>}

【讨论】:

    【解决方案3】:

    在此处阅读有关通过 Office 365 使用 SMTP 发送的更多信息: https://technet.microsoft.com/en-us/library/dn554323.aspx

    使用这样的身份验证方法,您无需设置 :domain。

    【讨论】:

      【解决方案4】:

      devise.rb 中我设置了"no-reply@******.com",我在smtp 设置中提到production.rb"noreply@*****.com"

      devise.rb 中的电子邮件ID 替换为"no-reply@*******.com""noreply@******.com" 后,现在可以正常工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-20
        • 1970-01-01
        • 1970-01-01
        • 2011-06-23
        • 2015-01-12
        • 1970-01-01
        • 1970-01-01
        • 2020-08-21
        相关资源
        最近更新 更多