Get a password for two-step verification with your Google account
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]
④ Return to the screen and [App Password] will be displayed in [Login to Google]. Set according to the screen.
⑤ A password will be issued (16 characters) We will use this password to authenticate your email account.
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
$ 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)
We will implement it in Ruby on Rails. Implementation of automatic sending function of Ruby on Rails mail
Recommended Posts