【问题标题】:Mail gets send from smtp username setting not from "from" method in ActionMailer rails邮件从 smtp 用户名设置而不是 ActionMailer rails 中的“from”方法发送
【发布时间】:2015-01-30 06:12:58
【问题描述】:

在 user_mailer.rb 中

class UserMailer < ActionMailer::Base
  default from: "email.1@gmail.com"
  def approved_mail(user)
    @user = user
    @greeting = "Hi"

    mail to: @user.email
  end
end  

在 development.rb 中

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "gmail.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: "email.2@gmail.com",
  password: ENV["GMAIL_PASSWORD"]
}  

我收到来自“email.2@gmail.com”的电子邮件,为什么不是来自“email.1@gmail.com”,等待澄清。

【问题讨论】:

    标签: ruby-on-rails-4 ruby-2.1


    【解决方案1】:

    smtp_settings中的user_name仅指用于连接SMTP服务器的认证名称。

    将此添加到您的development.rb

    config.action_mailer.default_options = { from: "email.2@gmail.com" }
    

    【讨论】:

    • 感谢您的解决方案,但我应该已经收到来自 user_mailer.rb 中指定地址的电子邮件,所以我想知道为什么 user_mailer 中的行'default from: "email.1@gmail.com"'。 rb 不工作。
    【解决方案2】:

    smtp_settings中,如果我们的邮件服务器需要认证,我们需要设置user_namepassword

    在您的情况下,您在 development.rb 文件中提供了'email.2@gmail.com' 的身份验证。因此,action mailer 将忽略 default from: "email.1@gmail.com",因为它无法对其进行身份验证。

    【讨论】:

    • 意思是,user_mailer.rb 中的 'from' 默认选项和 'smtp_settings > user_name' 应该相同 - 我的评论是真的还是我缺乏足够的理解
    猜你喜欢
    • 2018-12-05
    • 2013-12-17
    • 2014-07-09
    • 2011-12-31
    • 1970-01-01
    • 2011-08-11
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多