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
Related articles
- ruby on rails 6 - when i press new user registration, i get an error of no route matches [get] "/ users"
- ruby on rails implementation of purchase history page when two are purchased at the same time
- ruby on rails implementation of purchase history page when two are purchased at the same time
- ruby on rails - unable to get latitude/longitude from user registration
- ruby - [rails] implementation of search function
- ruby on rails - implementation of sales ranking function rails
- ruby - about implementation of tag function in rails
- ruby on rails - rails db registration activerecord :: associationtypemismatch in friendscontroller # create
- ruby on rails - implementation of validation function
- ruby on rails - i want to avoid displaying duplicate data for each shop
- ruby - about "activemodel :: unknownattributeerror" of rails
- ruby on rails 6 - rails6 activerecord :: recordinvalid in userscontroller # update
- ruby - [rails] i want to change the argument of link_to using conditional branching
- ruby on rails 6 - i changed the project name of rails, but it became inaccessible
- ruby on rails - i want to jump to the action of another controller with render
- ruby on rails - heroku: how to check the database_url used for regular backup
- ruby on rails - i want to deploy to aws ec2 server
- ruby on rails - i can't update rubygems
- ruby on rails 5 - i want to update the received parameters with nil
Related questions
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - i want to use the search method for active hash data
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- javascript - run multiple times with js + each do
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]
I will change the content of the question and ask the question again.