Home>

After registering as a user, I wrote the following code to send a registration completion email to the registered email address, but the email is not sent successfully.
Could you please tell me which part should be corrected so that it will be sent?
Thanks for your cooperation.
(In addition, I referred to this site when creating it (https://qiita.com/Yama-to/items/823baf26bba3193712ea))

Below is the code I have entered.
↓ development.rb

# --- Omitted --- #
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:'smtp.gmail.com',
    user_name:'email address',
    password:'password',
    authentication:'login',
    enable_starttls_auto: true
  }

↓ app/mailers/application_mailer.rb

class ApplicationMailer</pre>
<p><br />
↓ app/mailers/sample_mailer.rb</p>
<pre><code>class SampleMailer</pre>
<p><br />
↓ views/sample_mailer/send_when_update.html.erb</p>
<pre><code><! doctype html>
<html>
<head>
<meta content = "text/html;charset = UTF-8" />
<style type = "text/css">
    h2 {
      color: # e7454a;
    }
    p hr {
      color: # 2d2a24;
    }
</style>
</head>
<body>
 <% = @ user.name%>like 
<hr />
<p>
    Thank you for using the "Mail Test Management Bureau".
</p>
<p>
    Username:<% = @ user.name%><br />
</p>
<hr />
</body>
</html>


↓ views/sample_mailer/send_when_update.text.erb

===============================
<% = @ user.name%>
===============================
Thank you for using the "Mail Test Management Bureau".
Username:<% = @ user.name%>

↓ controllers/users_controller.rb

# --- Omitted --- #
def update
    @user = User.find (params [: id])
    if current_user.id! = @ user.id
      redirect_to user_path (current_user)
    else else
      if @ user.update (user_params)
        redirect_to user_path (@user)
        flash [: notice] = "You have updated user successfully."
      else else
        render: edit
      end
    end

    ↓ The following two lines are added this time.
    current_user.update (update_params)
    SampleMailer.send_when_update (current_user) .deliver
  end
  • Answer # 1

    I will change the content of the question and ask the question again.