[英]Errno::ECONNREFUSED - Connection refused - connect(2) for “localhost” port 25:
I am trying to reset the password with dynamic email server settings in rails 4 using devise.我正在尝试使用设计在 rails 4 中使用动态电子邮件服务器设置重置密码。
my_mailer.rb
class MyMailer < Devise::Mailer
helper :application
include Devise::Controllers::UrlHelpers
default template_path: 'devise/mailer'
def reset_password_instructions(record, token, opts={})
# Has been dynamically set in the mailer_set_url_options of application_controller.rb
# opts[:host] = Setup.email_url
opts[:address] = Setup.email_address
opts[:port] = Setup.email_port
opts[:domain] = Setup.email_domain
opts[:from] = Setup.email_username
super
end
end
But getting the same error, what can be the issue any help will be really helpful thank you :)但是遇到同样的错误,可能是什么问题,任何帮助都会非常有帮助,谢谢:)
First of all as per the screenshot首先根据截图
I think you are using gmail
as a provider.我认为您正在使用
gmail
作为提供商。
Please go to enviroments file( development.rb
or production.rb
).请转到环境文件(
development.rb
或production.rb
)。 I guess you are using development environment.我猜你正在使用开发环境。
Go to the file config/environments/development.rb
转到文件
config/environments/development.rb
config.action_mailer.default_url_options = { :host => "my.website.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'website.com',
user_name: 'user@website.com',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true
}
Please refer ThisDoc .请参考ThisDoc 。
hope it might help you希望它可以帮助你
I am not using Devise but had the same error when trying to Dynamically change the smtp_settings of my application mailer.我没有使用 Devise,但在尝试动态更改应用程序邮件程序的 smtp_settings 时遇到了同样的错误。 In my case the settings came from the database.
在我的情况下,设置来自数据库。 The way I made it work is by using
after_action
callback of ActionMailer
.我让它工作的方式是使用
ActionMailer
after_action
回调。 And to merge the settings for the delivery method of my mail并合并我的邮件投递方式的设置
Here is an example:下面是一个例子:
after_action do
self.delivery_method = SETTING_FROM_DB.delivery_method
settings = {
address: SETTING_FROM_DB.address,
port: SETTING_FROM_DB.port
# More setting if needed
}
self.mail.delivery_method.settings.merge! settings
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.