【问题标题】:Ruby on Rails End of File with SMTP带有 SMTP 的 Ruby on Rails 文件结尾
【发布时间】:2016-07-11 14:05:43
【问题描述】:

抱歉,如果答案在那里,但在我浏览过的许多类似帖子中,我还没有找到我正在寻找的答案。

我继承了一个 Ruby on Rails 应用程序,但它最近开始无法发送电子邮件。据我所知,这是由于 smtp 失败。

我想使用“myaccount@gmail.com”的 SMTP 设置从“do_not_reply@mydomain.com”发送电子邮件。

.../config/environments/production.rb 我有

ActionMailer::Base.smtp_settings = {                         
    :enable_starttls_auto => true,
    :address                        => 'smtp.gmail.com',
    :port                           => 587,             
    :authentication         =>  :plain,                
    :user_name                      => '<myaccount@gmail.com>'
    :password                       => '<mygmailpassword>'      
}

.../app/models/ 我有一个名为 user_notifier.rb 的文件,其中包含

class UserNotifier < ActionMailer::Base
    def signup_notification(user)
        setup_email(user)
        @subject += 'Please activate your new account'
        @body[:url] = "<mydomain.com>:8080/activate/#{user.activation_code}"
    end

    def activation(user)
        setup_email(user)
        @subject += 'Your account has been activated'
        @body[:url] = "<mydomain.com>:8080"
    end

    def reset_notification(user)
        setup_email(user)
        @subject += 'Link to reset your password'
        @body[:url] = "<mydomain.com>:8080/reset_password/#{user.reset_password_code}"
    end

    def login_reminder(user)
        setup_email(user)
        @subject += 'Login Reminder'
        @body[:url] = "<mydomain.com>:8080"
    end

    protected

    def setup_email(user)
        @recipients = "#{user.email}"
        @from = "<do_not_reply@mydomain.com>"
        @subject = "<subject>"
        @sent_on = Time.now
        @body[:user] = user
        bcc ["<myaccount@gmail.com>"]
    end
end

所有这些代码都曾经工作过,所以我不确定发生了什么变化。在我写这篇文章时,我意识到突然的故障可能与网络上的一些维护有关,所以我不知道这会如何影响事情。

编辑:按照 cmets 的要求添加了整个 UserNotifier

【问题讨论】:

  • 你能把你的完整UserNotifier类发上来吗
  • 当然。我刚刚添加了它。

标签: ruby-on-rails smtp


【解决方案1】:

嗯,其实我自己解决了这个问题。

我需要在 .../config/environments/production.rb

中添加:domain 选项

为什么它曾经在没有 :domain 的情况下工作,我仍然不知道,但我会选择功能性产品。

工作设置是

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-19
    • 2017-07-22
    • 2012-05-08
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    相关资源
    最近更新 更多