Topic: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

For some time now, folks have been trying to get ActionMailer to work with Gmail, which has been challenging due to the fact that Gmail requires tls, which Ruby and Rails for some time did not offer. Some plugins happened to address the issue, the people rejoiced. Then Ruby 1.8.7 came out and tls was prepackaged. I think you may have needed Rails to be of a version greater than or equal to some minimum for everything to work out of the box, but given that, all would be green meadows.

Well, seems that I'm still managing to have some trouble. I have set everything up in my environment.rb file as such

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {    
    :address              => 'smtp.gmail.com',    
    :port                 => 587,    
    :domain               => 'gmail.com',    
    :user_name            => 'sanjuancoop@gmail.com',    
    :password             => '**gmail password**',
    :authentication       => :plain,
    :enable_starttls_auto => true
  }

and am using the email authentication code from restful_authentication and I get the following error

Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first. 23sm1922646pzk.0

Have other people running 1.9.1 and 2.3.3 had issues with this or, on the contrary, gotten it to work properly? I would be great to know either way. I may end up having to resort to paying for smtp service elsewhere, but it would be nice if this worked.

Thanks for your time

Chris

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

It was a hell to setup rails 2.3.3 on ruby 1.8.7 with TLS. Although it is said in all docs, that you don't need plugins with ruby 1.8.7 or above (even the one I used says that), I've found that without this gem it won't work:
<pre>
sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com
</pre>

and put at the very end of your config/environment.rb (I mean outside of the Rails::Initializer.run section)
<pre>
require 'smtp-tls'

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "gmail.com",
   :authentication => :plain,
   :user_name => "gmailusername",  # don't put "@gmail.com" here, just your username
   :password => "gmailpawwsord",
   :enable_starttls_auto => true
</pre>

Hope it saves some time for others.

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

pre doesn't work here? sorry guys.. and there is a closing '}' after the last true of course. so again:

It was a hell to setup rails 2.3.3 on ruby 1.8.7 with TLS. Although it is said in all docs, that you don't need plugins with ruby 1.8.7 or above (even the one I used says that), I've found that without this gem it won't work:

sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com

and put at the very end of your config/environment.rb (I mean outside of the Rails::Initializer.run section)

require 'smtp-tls'

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "gmail.com",
   :authentication => :plain,
   :user_name => "gmailusername",  # don't put "@gmail.com" here, just your username
   :password => "gmailpawwsord",
   :enable_starttls_auto => true }

Hope it saves some time for others.

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

Thanks for the reply miklos.beky. I switched to SendGrid for SMTP service, so I stopped working on this, but if I come back around to it, I'll give your suggestion a whirl. Incidentally, SendGrid has very good plans including a free one with a 200 email per day limit. Once I go live, this won't be enough to keep things rolling, but it at least lets me get started developing. I've also found that whereas a lot of smtp services have data limits per day or month, these guys don't and the base payed plan is 10,000 emails per month for $10, which is very reasonable and leaves lots of room for growth. So, if you don't feel like mucking around with gems nd such and will need to scale up anyway, this could be a good route for you.

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

miklos.beky wrote:

pre doesn't work here? sorry guys.. and there is a closing '}' after the last true of course. so again:

It was a hell to setup rails 2.3.3 on ruby 1.8.7 with TLS. Although it is said in all docs, that you don't need plugins with ruby 1.8.7 or above (even the one I used says that), I've found that without this gem it won't work:

sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com

and put at the very end of your config/environment.rb (I mean outside of the Rails::Initializer.run section)

require 'smtp-tls'

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "gmail.com",
   :authentication => :plain,
   :user_name => "gmailusername",  # don't put "@gmail.com" here, just your username
   :password => "gmailpawwsord",
   :enable_starttls_auto => true }

Hope it saves some time for others.


THANK YOU SO MUCH!
After long hours of trying this and that from a bunch of incomplete "manuals", attempting to use local sendmail on Leopard, gmail smpt and whatnot, nothing worked. Shame on all others to keep incomplete manuals on their blogs.

You are the man! Hope this post gets indexed very soon by google so others can find it.

Respect dude!

SAVE MYSQL NOW, Go to: http://helpmysql.org

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

I was able to send messages via gmail on Ruby 1.8.7 and Rails 2.3.5., notably you need to add this to environment.rb, after the Initializer:

require 'tlsmail'
Net::SMTP.enable_tls( OpenSSL::SSL::VERIFY_NONE)


Works!

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

I think both solutions work with the issue that google's mail server's ssl key is self-signed or something like this. i'm not sure, but if that's the case, either shame on google or shame on the ca system as it is, since an open network (like our internet) would need a different approach on authenticity validation...

Re: ActionMailer, tls and Gmail in Rails 2.3.3 with Ruby 1.9.1

wow.. this might be an old post but I must thank miklos.beky for the great solution... it does work