Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionmailer not delivering mail, with rails 3

I am trying to make an application, that sends an email when user registers.

i put in the smtp settings for gmail in the config/application.rb file and the mail function looks like

mail(:to => "[email protected]", :subject => "Mail!", :from => "[email protected]", :content_type => "text/html")

now when i see the logs, i see that it says mail has been sent, but i never receive any mail at all...

also, when i call the mail deliver function, Emails.signed(@user).deliver, the form page does not redirect, but it works if i comment out the email sending code that is either

Emails.signed(@user).deliver

or

mail(:to => "[email protected]", :subject => "Mail!", :from => "[email protected]", :content_type => "text/html")

Thanks :)

Edit: development.rb

App::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_view.debug_rjs             = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

end
like image 904
Amit Avatar asked Aug 02 '10 22:08

Amit


People also ask

How do I send an email to ROR?

Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.


2 Answers

Somewhat late, but nevertheless maybe this will save someone a few hours of head banging. This is probably only relevant to sending emails from gmail. First, in order to help debugging the situation, set the following line in development.rb to true (assuming you're in development mode):

config.action_mailer.raise_delivery_errors = true

This will make ActionMailer not to silently ignore errors. When I did that, I realized gmail is refusing my username and password. I then went to my configuration file where I put all the Action Mailer config directives (for me it was in development.rb, there is probably a better place to put it), and noticed that :user_name was set to "admin" rather than "[email protected]". Changing it solved the problem. Here is my corrected part of development.rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'thedomain.com',
  :user_name            => '[email protected]',
  :password             => '<password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

References:

http://forums.pragprog.com/forums/43/topics/541 http://edgeguides.rubyonrails.org/action_mailer_basics.html

like image 56
AmitA Avatar answered Oct 21 '22 01:10

AmitA


Another thing not to forget: you have to restart the application after making changes in your environment config files. when using passenger this can quickly be missed :)

that's what solved my "problem" when ActionMailer didnt want to send emails without showing any errors..

like image 24
Peter Avatar answered Oct 21 '22 00:10

Peter