I made a Japanese version of Rails / devise automatic email

Introduction

The search method may be wrong, but I couldn't find the fixed phrase of the Japanese translation of devise's automatic email. So, I'm going to write an article about the fixed phrases used in my portfolio. I hope you find it helpful.

Premise

--Use environment variables (Gem of dotenv-rails) for the URL and inquiry email address to be described in the signature. --The subject of the email shall be translated into Japanese using the Gem of "devise-i18n" and "devise-i18n-views". ――The translated text is not a literal translation, but a text that is commonly used in Japan. I tried not to make any mistakes or deficiencies, but if you are kind, please feel free to point out any mistakes or deficiencies. ――Since I learned later that I18n support, this article does not support I18n in the text. Only the translated text is written directly in the template file. If you want to support multiple languages, please refer to the following.

https://qiita.com/tiktak/items/a70ef7940fa4710f37cb

version information

translation

The following 5 files are preset in devise.

--Membership registration confirmation email: ( `confirmation_instructions.html.erb```) --Change notification email to the original email address: (```email_changed.html.erb```) --Password change completion email: ( password_change.html.erb```) --Email address change confirmation email: (`` reset_password_instructions.html.erb) --Account lock notification email: (unlock_instructions.html.erb```)

This translation is shown below.

Membership registration confirmation email

erb:app/views/devise/mailer/confirmation_instructions.html.erb



<p>* This email is an automatically sent email.</p>

<p><%= @email %>Mr</p>

<p>「<%= ENV['APP_NAME'] %>This is the secretariat.</p>
<p>This time"<%= ENV['APP_NAME'] %>Thank you for registering.</p>

<p>Please check your account email from the link below.</p>

<p><%= link_to 'Click here to check your account email', confirmation_url(@resource, confirmation_token: @token) %></p>


<p>* This email will not be delivered even if you reply. For inquiries, please start the app and click "Inquiries".</p>

<p>
Those who received this email even though they don't remember<br>
We apologize for the inconvenience. We apologize for the inconvenience, but please contact us at the email address below.<br>
</p>
<p><%= ENV['MAIL_BCC'] %></p>

<p>――――――――――――――――――――――――――――――</p>
<%= ENV['APP_NAME'] %><br>
URL : <%= ENV['WEB_PROTOCOL'] %>://<%= ENV['WEB_HOST'] %><br>
Mail : <%= ENV['MAIL_BCC'] %><br>
<p>――――――――――――――――――――――――――――――</p>



Change notification email to the original email address

erb:app/views/devise/mailer/email_changed.html.erb



<p>* This email is an automatically sent email.</p>

<p><%= @email %>Mr</p>

<p>「<%= ENV['APP_NAME'] %>This is the secretariat.</p>

<% if @resource.try(:unconfirmed_email?) %>
  <p>The registered email address is<%= @resource.unconfirmed_email %>We will inform you that it has been changed to.</p>
<% else %>
  <p>The registered email address is<%= @resource.email %>We will inform you that it has been changed to.</p>
<% end %>

<p>
Those who received this email even though they don't remember<br>
We apologize for the inconvenience. We apologize for the inconvenience, but please contact us at the email address below.<br>
</p>
<p><%= ENV['MAIL_BCC'] %></p>

<p>――――――――――――――――――――――――――――――</p>
<%= ENV['APP_NAME'] %><br>
URL : <%= ENV['WEB_PROTOCOL'] %>://<%= ENV['WEB_HOST'] %><br>
Mail : <%= ENV['MAIL_BCC'] %><br>
<p>――――――――――――――――――――――――――――――</p>


Password change completion email

erb:app/views/devise/mailer/password_change.html.erb


<p>* This email is an automatically sent email.</p>

<p><%= @resource.email %>Mr</p>

<p>「<%= ENV['APP_NAME'] %>This is the secretariat.</p>

<p>We will inform you that your password has been changed.</p>
<p>We look forward to working with you in the future.</p>

<p>
Those who received this email even though they don't remember<br>
We apologize for the inconvenience. We apologize for the inconvenience, but please contact us at the email address below.<br>
</p>
<p><%= ENV['MAIL_BCC'] %></p>

<p>――――――――――――――――――――――――――――――</p>
<%= ENV['APP_NAME'] %><br>
URL : <%= ENV['WEB_PROTOCOL'] %>://<%= ENV['WEB_HOST'] %><br>
Mail : <%= ENV['MAIL_BCC'] %><br>
<p>――――――――――――――――――――――――――――――</p>



Password change confirmation email

erb:app/views/devise/mailer/reset_password_instructions.html.erb


<p>* This email is an automatically sent email.</p>

<p><%= @resource.email %>Mr</p>

<p>「<%= ENV['APP_NAME'] %>This is the secretariat.</p>

<p>We will inform you that your password has been changed.</p>
<p>We look forward to working with you in the future.</p>

<p>
Those who received this email even though they don't remember<br>
We apologize for the inconvenience. We apologize for the inconvenience, but please contact us at the email address below.<br>
</p>
<p><%= ENV['MAIL_BCC'] %></p>

<p>――――――――――――――――――――――――――――――</p>
<%= ENV['APP_NAME'] %><br>
URL : <%= ENV['WEB_PROTOCOL'] %>://<%= ENV['WEB_HOST'] %><br>
Mail : <%= ENV['MAIL_BCC'] %><br>
<p>――――――――――――――――――――――――――――――</p>


Account lock notification email

erb:app/views/devise/mailer/unlock_instructions.html.erb



<p>* This email is an automatically sent email.</p>

<p><%= @resource.email %>Mr</p>

<p>「<%= ENV['APP_NAME'] %>This is the secretariat.</p>

<p>The number of failed sign-ins has reached the limit and your account has been locked.</p>

<p>Click the link below to unlock your account.</p>

<p><%= link_to 'Unlock your account', unlock_url(@resource, unlock_token: @token) %></p>

<p>
Those who received this email even though they don't remember<br>
We apologize for the inconvenience. We apologize for the inconvenience, but please contact us at the email address below.<br>
</p>
<p><%= ENV['MAIL_BCC'] %></p>

<p>――――――――――――――――――――――――――――――</p>
<%= ENV['APP_NAME'] %><br>
URL : <%= ENV['WEB_PROTOCOL'] %>://<%= ENV['WEB_HOST'] %><br>
Mail : <%= ENV['MAIL_BCC'] %><br>
<p>――――――――――――――――――――――――――――――</p>

Method of verification

The automatic e-mail sent for each page and the verification method are described below.

--Membership registration page --Member registration confirmation email --User information edit page --Password change completion email --Email address change confirmation email --Change notification email to the original email address --Login page --Account lock notification email

Member registration page

  1. Temporarily register as a member and send a "member registration confirmation email"

User information edit page

  1. Change your password and send a "password change completion email"

  2. Change your e-mail address and send a "e-mail address change confirmation e-mail"

  3. Send a "email address change confirmation email" when the account email address has been changed in the "email address change confirmation email"

config/initializers/devise.rb


  #・ ・ ・ Omitted

  # Send a notification to the original email when the user's email is changed.
  config.send_email_changed_notification = true # <=If set to true, "email address change confirmation email" will be sent to the original email.

  #・ ・ ・ Omitted

Login page

  1. Fail the login for the set number of times and send an "account lock notification email"

config/initializers/devise.rb


  #・ ・ ・ Omitted

  # Number of authentication tries before locking an account if lock_strategy
  # is failed attempts.
  config.maximum_attempts = 20 #<=Means account lock after 20 failures

  #・ ・ ・ Omitted

config/initializers/devise.rb


  #・ ・ ・ Omitted

  # Defines which strategy will be used to unlock an account.
  # :email = Sends an unlock link to the user email
  # :time  = Re-enables login after a certain amount of time (see :unlock_in below)
  # :both  = Enables both strategies
  # :none  = No unlock strategy. You should handle unlocking by yourself.
  config.unlock_strategy = :email # <= 「:If you select "email", you can recover your account with "account lock notification email".

  #・ ・ ・ Omitted

Challenges / places I didn't understand

――I thought it would be even better if I18n was supported. I will try next time.

finally

It was an opportunity to know when the Devise email was sent.

reference

Devise.rb configuration file item summary

Recommended Posts

I made a Japanese version of Rails / devise automatic email
Rails: Japanese localization of validation messages including devise
[Rails] I made a draft function using enum
I made a LINE bot with Rails + heroku
I made a portfolio with Ruby On Rails
I made a server side of an online card game ⑤
[Rails] Introduction of devise Basics
I made a server side of an online card game ③
I made a development environment with rails6 + docker + postgreSQL + Materialize.
I made a server side of an online card game ⑥
I made a chat app.
[Japanese localization of gem: devise]
I tried JAX-RS and made a note of the procedure
I made a server side of an online card game ④
I made a server side of an online card game ②
Rails was difficult, so I made something like a controller of Spring Framework to take a break
I made a SPA with Rails + Nuxt.js for half a year of self-study, so please take a look.
I checked the automatic unit test creation tool (end of 2019 version)
I made a reply function for the Rails Tutorial extension (Part 1)
I get a Ruby version error when I try to start Rails.
I made a gem to post the text of org-mode to qiita
I made a method to ask for Premium Friday (Java 8 version)
I made a reply function for the Rails Tutorial extension (Part 5):
I made a tool to output the difference of CSV file
[Rails] Japanese localization of error messages
Ruby: I made a FizzBuzz program!
I made a shopify app @java
I made a GUI with Swing
Japanese localization of error messages (rails)
I made a simple recommendation function.
I made a matching app (Android app)
I made a package.xml generation tool.
[Android] I made a pedometer app.
[Rails] I want to send data of different models in a form
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I made a reply function for Rails Tutorial extension (Part 2): Change model
[Ruby] I made a simple Ping client
Is there a numeric version of include?
I made a risky die with Ruby
I made a plugin for IntelliJ IDEA
[Ruby on Rails] Japanese notation of errors
I made a rock-paper-scissors app with kotlin
Rails Basics of creating a new application
I made a calculator app on Android
I made a new Java deployment tool
[Vue.js] Implementation of menu function Implementation version rails6
I made a rock-paper-scissors app with android
[Rails] How to translate devise into Japanese
I made a bulletin board using Docker 1
Rails6 I want to make an array of values with a check box
I made a sample of how to write delegate in SwiftUI 2.0 using MapKit