Reputation: 1232
I'm trying to send an email with Rails 4. The server raises no error but I cannot receive the mail in my mailbox... Here is my configuration :
environnements/development.rb
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-reply@website.com'}
I'm sending the email like this :
user_mailer.rb
def deliver_password_reset_instructions(user)
mail :to => user.email, :subject => 'Instructions pour la reinitialisation de votre mot de passe'
end
user.rb
def deliver_password_reset_instructions!
reset_perishable_token!
UserMailer.deliver_password_reset_instructions(self)
end
Does anybody have an idea about why it is not sending the email?
Upvotes: 1
Views: 1751
Reputation: 25049
Your problem is that you're generating an email, but then not actually sending it.
UserMailer.deliver_password_reset_instructions(self).deliver
Will actually deliver the email you are creating.
Read over http://guides.rubyonrails.org/action_mailer_basics.html#walkthrough-to-generating-a-mailer (section 2.1.4 - Calling the Mailer) for more details about how to use mailers in your app.
Edit: deliver
has been deprecated in Rails 4.2, in favour of either deliver_now
or deliver_later
. For the same behaviour as deliver
from previous versions of Rails, you should use deliver_now
- deliver_later
is meant to be used with ActiveJob and a background job processor.
Upvotes: 4