This application was generated with the rails_apps_composer gem:
https://github.com/RailsApps/rails_apps_composer
provided by the RailsApps Project:
http://railsapps.github.io/
In order to set expiration time to 1 hour, add ‘devise :timeoutable, :timeout_in => 1.hour’ to ‘app/models/user.rb’
First make the file controllers/mailers/user_mailer.rb and insert the following code:
class UserMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
def confirmation_instructions(record, token, opts={})
opts[:from] = 'my_custom_from@domain.com'
# opts[:reply_to] = 'my_custom_from@domain.com'
super
end
end
Open config/initializers/devise.rb and add the following code:
config.mailer = 'UserMailer'
Make the file app/views/devise/mailer/confirmation_instructions.html.erb and insert the following code:
<p>Hi <%= @user.name %></p> <p>Welcome <%= @email %>!</p> <p>You can confirm your account email through the link below:</p> <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
configure settings like the bellowings in config/environments/development.rb:
config.action_mailer.smtp_settings = {
address: "127.0.0.1",
port: 1025,
domain: Rails.application.secrets.domain_name,
authentication: "plain",
enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => '127.0.0.1:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
# Send email in development mode?
config.action_mailer.perform_deliveries = true
To test the setup in development install the mailcatcher gem, that you will use as a SMTP server in development, catching all incoming mails and displaying them on http://localhost:1080/:
gem install mailcatcher
Once installed start the mailcatcher server with the command:
mailcatcher
A toy SMTP server will be running on port 1025 catching emails and displaing them on HTTP port 1080.