I'm using Devise for authentication, and I'm confused on how to set up mail along with it. Should you still be creating your own mailer and开发者_开发百科 initializer file, or should you be sending all mail through Devise? Where do you go in Devise to create the email template and the method for sending the email?
I realize this is kind of a broad question, so essentially I'm asking what is the best way to set up mail with Devise?
Also, if you wanted to send an email to a user after they have confirmed their email, how would you do this?
Devise does create it's own Mailer--if you take a look on GitHub https://github.com/plataformatec/devise/blob/master/app/mailers/devise/mailer.rb you can see that it comes with a bunch of methods already packaged in.
You can go ahead and generate the views for these methods using the command
rails g devise views
and then edit them.
If you would like to send additional email messages you should create your own Mailer to do so. I would recommend http://edgeguides.rubyonrails.org/action_mailer_basics.html . It's a pretty good overview of how to set up a mailer from the ground up.
Devise creates the mailer and email templates for you, so you don't have to worry about that. However, if you want to change the email templates, install devise views using the command:
rails g devise:views
This will add a new "devise" folder in your views. You can find all the email templates in the mailer folder under views/devise.
Use the confirmable attribute to send confirmation emails to users post registration. By default, this attribute is commented out. So, once you install devise using the command rails g devise:install, go to db/migrate and locate the devise_create_users migration and uncomment the following lines:
t.confirmable
and
add_index :users, :confirmation_token, :unique => true
.
Once done, migrate your database.
Now go to your user model and check if devise has the :confirmable attribute, if not add it and you are all set.
精彩评论