You will learn how to send emails in Ruby on Rails Project
You will learn how to make forgot password using devise
You will learn how we setup mail clients with SMTP connection
You will learn the configuration needed for sending the emails in Ruby on Rails Project
Requirements
OS: Ubuntu/Mac OS
A text editor like sublime
Basic understanding about Ruby on Rails
Email account of Gmail
And for better understanding must read my part 1 of this tutorial (link added in curriculum)
Difficulty
Intermediate
Tutorial Contents
Hello and welcome to the 2nd part of the tutorial. In this tutorial, we are going to make configurations in our app to send emails from app and we also make forgot password functionality using devise. So let's start the tutorial.
First of all run rails server in the project we make in part 1 of this tutorial.
we know how to generate the devise views as we discussed in the previuos tutorial.
Devise by defaut gave us the forgot password page but we can overwrite it, for that go to your app in the editor > views > users > password > new
You will get this form:
<h2>Forgotyourpassword?</h2><%=form_for(resource,as:resource_name,url:password_path(resource_name),html:{method::post})do|f|%><%=devise_error_messages!%><divclass="field"><%=f.label:email%><br/><%=f.email_field:email,autofocus:true,autocomplete:"email"%></div><divclass="actions"><%=f.submit"Send me reset password instructions"%></div><%end%>
Now open your localhost:3000/user/password/new in your url to check forgot password is working or not. You will get a error like the below image because by default hostname is set to blank in devise.
So lets setup our host in rails app to make forgot password functionality working in our app.
Step-1
Open gmail account
Click Settings button which is present at the tip right corner
Click the Forwarding and POP/IMAP tab
In the "IMAP Access" section, select Enable IMAP
Click Save Changes
Step-2
Add a file under mailer and name it application_mailer.rb
Open rails application in the editor (sublime), if you have setup the app please follow the previous tutorial.
Then go to our environment folder then development.rb file because we are on the local system thats why we configure only in the developement file, when we will going live then production.rb will be changed till then do not change anything in this file
Next is copy the previous code under the Rails.application.configure do