Reputation: 615
I am trying to reset the password with dynamic email server settings in rails 4 using devise.
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 :)
Upvotes: 2
Views: 10466
Reputation: 12320
First of all as per the screenshot
I think you are using Gmail as a provider.
Please go to enviroments file(development.rb
or production.rb
). I guess you are using development environment.
Go to the file 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: '[email protected]',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true
}
Please refer to this doc.
Upvotes: 2
Reputation: 651
I am not using Devise but had the same error when trying to Dynamically change the smtp_settings of my application mailer.
In my case the settings came from the database.
The way I made it work is by using after_action
callback of ActionMailer
. 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
Upvotes: 0