Use ActionMailer to send a welcome email when you register.
Implementation of login function using devise.
The sender of the welcome email is Gmail.
Description of how to set ActionMailer in config / environments / development.rb.
development.rb
Rails.application.configure do
#---Omission---#
 config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    port:                 587,
    address:              'smtp.gmail.com',
    domain:               'gmail.com',
    user_name:            'Source address',
    password:             'App password',
    authentication:       :plain,
    enable_starttls_auto: true
  }
For the app password, issue the first 16-digit password with 2-step authentication set, and enter it in the app password. I have referred to the following. -[Get password for Google mail application] (https://qiita.com/miriwo/items/833d4189140831c5d039) ・ [How to turn on Google two-step verification] (https://qiita.com/miriwo/items/0331e7241710fb4759fe)
$ rails g mailer UserNotice
app/mailers/user_notice_mailer.rb
class UserNoticeMailer < ApplicationMailer
  def send_signup_email(user)
    @user = user
    mail to: @user.email, subject: "Membership registration is complete."
  end
end
app/views/user_notice_mailer/send_signup_email.text.erb
Welcome<%= @user.name %>Mr
Thank you for registering for an account.
app/models/user.rb
#---add to---#
  after_create :send_welcome_mail
 
  def send_welcome_mail
    UserNoticeMailer.send_signup_email(self).deliver
  end
You can use after_create to call a method to send an email after a new User has been created.
You should now receive a welcome email.
Recommended Posts