Ruby 在 Rails 文件结尾,SMTP
Ruby on Rails End of File with SMTP
抱歉,如果答案在那里,但在我浏览的许多类似帖子中,我没有找到我正在寻找的答案。
我在 Rails 上继承了一个 Ruby 应用程序,它最近开始无法发送电子邮件。据我所知,这是由于 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
所有这些代码都曾经有效,所以我不确定发生了什么变化。在我写这篇文章时,我意识到突然的故障可能与网络上的某些维护相对应,所以我不知道这会对事情产生怎样的影响。
编辑:根据评论
中的要求添加了整个 UserNotifier
class
好吧,其实我自己解决了这个问题。
我需要在 .../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>'
}
抱歉,如果答案在那里,但在我浏览的许多类似帖子中,我没有找到我正在寻找的答案。
我在 Rails 上继承了一个 Ruby 应用程序,它最近开始无法发送电子邮件。据我所知,这是由于 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
所有这些代码都曾经有效,所以我不确定发生了什么变化。在我写这篇文章时,我意识到突然的故障可能与网络上的某些维护相对应,所以我不知道这会对事情产生怎样的影响。
编辑:根据评论
中的要求添加了整个UserNotifier
class
好吧,其实我自己解决了这个问题。
我需要在 .../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>'
}