Refer to Http://guides.rubyonrails.org/action_mailer_basics.html
In the security of your Gmail account, start with two-step verification (Link: https://myaccount.google.com/security) to generate an application-specific password, which you need to use later.
Enter the root of the rails project under the console and execute rails generate mailer Usermailer
Locate the app/mailers/user_mailer.rb file, such as:
In the third step, you can see the addition of the Send_email method in Usermailer, then you need to create the corresponding Mailer view, under the App/views/user_mailer folder (because some mail clients do not support HTML, So create a text at the same time, two send together, and the method name is consistent, when called Send_email, the corresponding view will be used. Usermailer is a controller, Send_email is Action,send_email.html.erb and Send_email.text.erb is the corresponding view.
Send_email.html.erb Content
Send_email.text.erb's content is to remove all the HTML tags in the Send_email.html.erb, leaving only the text, such as:
Now that the Controller#action view is available, because it is just a simple test, the model does not add, just change the action to the corresponding model of the mail or other.
Next, configure the Gmail SMTP server in the Config/application.rb file, such as (because Gmail needs fq to test, so in real development, the configuration of the SMTP server for Gmail can be placed in the Production.rb file, In test.rb and development.rb files with other mailboxes instead, I use the QQ SMTP server, as long as the QQ in the SMTP service, and get QQ client's private password)
SMTP Service configuration for QQ
The final step is to send a message by calling UserMailer.send_email.deliver_now
UserMailer.send_email.deliver_now
Because of the use of the Gmail SMTP server, the test needs FQ, so the local can not be tested. However, I can successfully send the message on my deployment to Heroku.
Ruby on Rails send mail using Gmail's SMTP