device login function [Rails] Try to introduce devise
Email authentication function [Devise] Email authentication sign-up / in / out function I want to implement email authentication with devise [Rails]
The above two functions have been implemented.
Create "mailer.rb" in "app/controllers/users". Inherit the mailer of device.
mailer.rb
class Users::Mailer < Devise::Mailer
end
Set "config/initializers/devise.rb"
devise.rb
config.mailer = 'Users::Mailer'
Put the image you want to insert in "/ app/assets/images/mailer /". Add a method to insert in HTML format mail to "mailer.rb" created earlier.
mailer.rb
class Users::Mailer < Devise::Mailer
before_action :add_image
private
def add_image
images = ['***.png', '***.jpg']
images.each do |img|
attachments.inline[img] = File.read("#{Rails.root}/app/assets/images/mailer/" + img)
end
end
end
Modify the file [/app/views/users/mailer/confirmation_instructions.html.erb "
ruby:confirmation_instructions.html.erb
<p>Welcome <%= @email %>!</p>
<p>Thank you for registering as a member.</p>
<%= image_tag attachments['***.png'].url, alt: "***" %>
<%= image_tag attachments['***.jpg'].url, alt: "***" %>
<p><%= link_to 'Account activation', confirmation_url(@resource, confirmation_token: @token) %></p>
The image is inserted when you register as a member here.
that's all. Thank you for reading this far.
Customize email templates (Mailer view) such as password reset in Rails Devise (https://easyramble.com/customize-mail-template-of-devise.html)
How to customize Devise authentication email
Post images by HTML email [rails] [Beginner]
Production environment [Rails] Email sending settings ~ Using gmail ~
Recommended Posts