【发布时间】: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