【问题标题】:Actionmailer - how can I set up "from" part?Actionmailer - 我如何设置“来自”部分?
【发布时间】:2012-05-08 23:07:56
【问题描述】:

这是我在/config/initializers/setup_mail.rb 中的配置文件:

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

这是Mailer's 类和我使用的方法:

class Notifierpass < ActionMailer::Base
  default from: "no-reply@my-domain.com"

  def forgot_password(user)    
    @reset_password_link = reset_password_url(user.perishable_token)

    mail(:from => "no-reply@my-domain.com", :to => user.email, :subject => "New passwordt")  
  end
end

发送电子邮件正常,我的问题是,在电子邮件的字段中 From 始终是 my_user_name 而不是 no-reply@my-domain.com。

问题出在哪里?为什么还用我的gmail名字?

【问题讨论】:

    标签: ruby-on-rails-3 email actionmailer


    【解决方案1】:

    GMail 只允许您从您的帐户或您已正确配置的其他电子邮件地址发送电子邮件。要从备用电子邮件地址发送,您需要将其添加到 Gmail 设置中。您只能添加您已经可以接收的地址。

    【讨论】:

    • 对不起老兄,我刚在哪里看到你,对此有相同的解释 +1
    【解决方案2】:

    当您连接到 gmail 的 smtp 服务器时(如在您的配置中),authentication_information 已经分配,​​因为您将使用具有已知电子邮件地址的某个 user_id 发送电子邮件。因此 google 将不接受任何 :from => "value" 但它会将 :from 参数与 auth_info 返回的电子邮件相匹配。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2011-08-12
      • 2014-01-06
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 2013-02-21
      • 2011-01-31
      相关资源
      最近更新 更多