Need help configuring Net::SMTP for Gmail in Ruby

Hey everyone,

I’m stuck trying to set up Net::SMTP to work with Gmail in Ruby. I’ve looked at some old examples from a few years back, but they’re not working with the latest 1.8.7 release. I’m getting this error:

SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol

I’m not really familiar with SSL in SMTP, so I’m a bit lost. The Net::SMTP docs don’t cover all the OpenSSL::SSL context options either.

Has anyone successfully set this up recently? I’d love some up-to-date info or examples that go beyond the basics. Thanks for any help!

I experienced a similar issue when configuring Net::SMTP for Gmail. I discovered that using TLS instead of SSL is necessary because older SSL protocols are no longer supported. It was important to update to a more recent version of Ruby, as relying on 1.8.7 can lead to compatibility problems. Adjusting the settings in my Google account to allow less secure access was also part of the solution. I then used a configuration that initialized Net::SMTP on smtp.gmail.com, port 587, enabled starttls_auto, and started the session with my credentials. Using an app-specific password when two-factor authentication is enabled further ensured a stable connection. A configuration like the following helped:

require 'net/smtp'

smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls_auto
smtp.start('gmail.com', '[email protected]', 'your_password', :login)

hey mate, ive been there too. make sure ur using TLS not SSL, gmail doesnt like the old stuff. also, upgrade ur ruby version, 1.8.7 is ancient! try this:

smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls
smtp.start(domain, email, password, :login)

works like a charm for me. good luck!