Ruby on Rails Email automatic sending function setting (using gmail)

Things to do

Get a password for two-step verification with your Google account

procedure

You will need to get a Google account. I turned on the two-step authentication of the gmail account and set it after obtaining the dedicated authentication password.

① Open a browser with the Google account used for sending, open the tab on the upper right and open the account.

(2) Select [Security] from the menu on the left side of the screen to open the security setting screen.

③ Select [2-step authentication process] in [Login to Google] and set according to the screen. [Try it] ⇨ [Password] ⇨ [Continue] ⇨ [Confirmation contact will be sent to your mobile phone] ⇨ [Register backup method] ⇨ [Enter the code you received on your mobile phone] ⇨ [Enable] 3.png

④ Return to the screen and [App Password] will be displayed in [Login to Google]. Set according to the screen. 4.png

⑤ A password will be issued (16 characters) We will use this password to authenticate your email account.

Rails config file editing

Email sending settings are defined in the configuration file for each environment under config / environment.

[Folder structure]  config   ∟environments ∟development.rb ・ ・ ・ Development environment ∟product.rb ・ ・ ・ Production environment

Rails.application.configure do
  config.action_mailer.raise_delivery_errors = true  #Change from false to true
 #Omission#
  config.action_mailer.delivery_method = :smtp 
  config.action_mailer.smtp_settings = {
    address: 'smtp.gmail.com',
    domain: 'smtp.gmail.com',
    port: 587,
    user_name: Rails.application.credentials.gmail[:user_name],
    password: Rails.application.credentials.gmail[:password],
    authentication: 'login',
    enable_starttls_auto: true
  }
end

Setting environment variables

$ sudo EDITOR=vim rails credentials:edit

Add the following to the environment variables.

gmail:
  user_name: [email protected] 
  #Enter the address of the Google account you registered earlier
  password: aaaabbbbccccdddd
  #Enter the issued password (16 characters)

next time

We will implement it in Ruby on Rails. Implementation of automatic sending function of Ruby on Rails mail

Recommended Posts

Ruby on Rails Email automatic sending function setting (using gmail)
Ruby on Rails Email automatic sending function implementation
[Ruby on Rails] Introduced paging function
[Ruby on Rails] CSV output function
[Ruby on Rails] Comment function implementation
[Ruby on Rails] DM, chat function
[Ruby on Rails] Search function (not selected)
[Rails] Addition of Ruby On Rails comment function
[Ruby on Rails] Code check using Rubocop-airbnb
[Ruby on Rails] Follow function implementation: Bidirectional
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Image slideshow using Skippr
[Ruby on rails] Implementation of like function
[Ruby on Rails] Logical deletion (withdrawal function)
Implementation of Ruby on Rails login function (Session)
Ruby on Rails address automatic input implementation method
[Ruby on Rails] Post editing function (update, delete)
[Ruby on Rails] Solving the addiction when setting crontab using whenever in EC2
How to implement image posting function using Active Storage in Ruby on Rails
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
[Ruby on Rails] Asynchronous communication of posting function, ajax
Implementation of Ruby on Rails login function (devise edition)
[Ruby on Rails] Posting score ranking function (whole display)
[Ruby on Rails] Implementation of tagging function/tag filtering function
[Ruby on Rails] Common processing between controllers (using concaves)
[Ruby on Rails] Post image preview function in refile
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
[Ruby on Rails] Search function (model, method selection formula)
Try using the query attribute of Ruby on Rails
Ruby on rails learning record -2020.10.03
Search function using [rails] ransack
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Bookmark (favorite registration, like) function: One direction
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
[Rails] Create an email sending function with ActionMailer (complete version)
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
A note about the seed function of Ruby on Rails
[Ruby on Rails] Easy scroll animation of javascript (using ScrollReveal.js)
[Ruby on Rails] Implement login function by add_token_to_users with API
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ajax bookmark function using Rails
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
[Ruby on Rails] Infinite scrolling using gem kaminari and jscroll
I want to add a browsing function with ruby on rails
Ruby on Rails for beginners! !! Post list / detailed display function summary
[Rails] Implementation of coupon function (with automatic deletion function using batch processing)
[Ruby on Rails] Posting function that only logged-in users can post
(Ruby on Rails6) Create a function to edit the posted content
Ruby on Rails Overview (Beginner Summary)