2016-06-21 89 views
0

如果答案已经存在,但是在我浏览过的许多类似帖子中,我还没有找到我正在寻找的答案。Ruby on Rails用SMTP结束文件

我已经继承了Ruby on Rails应用程序,它最近开始无法发送电子邮件。从我能收集到的,这是由于smtp失败。

我想使用“[email protected]”发送来自“[email protected]”的电子邮件用于SMTP设置。

... /配置/环境/ production.rb我已经

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

... /应用/型号/我呼吁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 = "<[email protected]>" 
     @subject = "<subject>" 
     @sent_on = Time.now 
     @body[:user] = user 
     bcc ["<[email protected]>"] 
    end 
end 

所有这些代码曾经工作,所以我不知道什么改变了。当我写这篇文章时,我意识到突发故障可能与网络上的某些维护相对应,所以我不知道这会对事情产生什么影响。

编辑:添加整个UserNotifier类如评论

+0

可能您发布完整'UserNotifier'类 – oreoluwa

+0

肯定。我刚刚添加了它。 – Will

回答

0

要求嘛,其实我设法解决这个我自己。

我需要添加:domain选项... /配置/环境/ production.rb

为什么不:domain我仍然不知道曾经工作过,但我还是要仅仅有功能性产品。

工作设置为

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