views:

220

answers:

3

Hi,

I'm kind of new at ruby on rails, and I've read many tutorials about this, but I still can't figure out what's wrong.

I already set up the environment.rb with the following lines at the bottom:

ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.default_content_type = "text/html"

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :port           => 25,
  :domain         => 'gmail.com',
  :authentication => :login,
  :user_name      => '[email protected]',
  :password       => 'mypassword'
}

Then, I've got some code that came with the baseApp I'm using, and it does the following:

UserMailer.deliver_forgot_password(self)

Where self is the user object, that contains the email, login, etc.

That method(which belongs to the UserMailer class) has the following code:

  def forgot_password(user)
    setup_email(user)
    @subject += "Forgotten password instructions"
    #{user.password_reset_code}
    @body[:url]  = "http://#{Setting.get(:site_url)}/users/reset_password/#"

  end

protected
    def setup_email(user)
      @recipients  = "#{user.email}"
      @from        = "#{Setting.get(:support_name)} <#{Setting.get(:support_email)}>"
      @subject     = "[#{Setting.get(:site_name)}] "
      @sent_on     = Time.now
      @body[:user] = user

      # Get Settings
      [:site_name, :company_name, :support_email, :support_name].each do |id|
        @body[id] = Setting.get(id)
      end
    end

Well, the emails are fine, I've already checked them doing raise inspect, but it's not sending...and it doesn't throw me an exception either.

Now I'm getting Errno::ECONNREFUSED error when trying to send an email. What's wrong now?

Thanks, Brian

+1  A: 

Gmail port should be 587 or 465.

and add

:tls => true,

Do you have the ActionMailerTLS Gem installed ?

Mark Robinson
It doesn't work either :(
Brian Roisentul
this question may help you http://stackoverflow.com/questions/801005/successfully-installed-actionmaileroptionaltls-to-send-using-gmail
Mark Robinson
Thanks Mark. I'll try installing action_mailer_tls plugin.My only doubt regarding that is I don't get the error mentioned in that post. Do I have to install it anyway? Maybe I have the error notifier disabled...
Brian Roisentul
How do I install that gem? I'm using Windows 7
Brian Roisentul
Ok. I've downloaded the zip file from the its website and followed the instructions explained here: http://github.com/openrain/action_mailer_tlsWhat I didn't do is the step 1, because I don't know where to write that..and I manually copied the plugin in the plugins folder instead, and NetBeans recognized it, but it's still not working.
Brian Roisentul
+1  A: 

The new way of doing this as of rails 2.3.2 is

:enable_starttls_auto => true

No need for additional plugins.

KJF
True. I've just read this somewhere else too. But it's still not working.All I've got configured for this is:- At development.rb:config.action_mailer.delivery_method = :smtpconfig.action_mailer.perform_deliveries = trueconfig.action_mailer.smtp_settings = { :enable_starttls_auto => true, :address => "smtp.gmail.com", :port => 587, :domain => "domain.com", :user_name => "[email protected]", :password => "password", :authentication => :plain}Do I need something else to make this work? I don't get any exception...I just don't receive the email.
Brian Roisentul
I see this is set up in development.rbDo you have the line config.action_mailer.raise_delivery_errors = trueThis is set to false by default, maybe try setting it to true and seeing if action mailer gives you any delivery errors.
KJF
+1  A: 

On my Mac, I had to turn on postfix to get emails to send. Maybe you don't have a similar mail program turned on capable of sending emails. What that is for Windows 7, I do not know.

danengle
I don't know either. I guess maybe it doesn't work because of my ruby version. When I right click my project I see "Ruby Platform: Built-in JRuby 1.2.0". I can choose either that or 1.8.6-p287 Should I download a newer vesion?
Brian Roisentul
If you can see the email printed out in your logs, your ruby version shouldn't be the problem. Maybe you need IIS or sendmail for Windows, but I'm not familiar with Windows development. I don't want to start a flame war, but you may want to consider creating a Linux based virtual machine and do your developing there. Developing on Linux or Mac OS X is a much better experience and there will be more people familiar with the environment who will be able to help you with these kind of situations.
danengle