SMTP with Gmail in 1.9.2

A

Alex Baranosky

Hi guys,

I've got a program that has been working fine running 1.8.6 using the
smtp_tls gem to send emails via my gmail account. I'v now removed the
smtp_tls gem because I was under the impression it was included in Ruby
core now.

I've upgraded to 1.9.2 and the code I wrote is now failing:

require 'net/smtp'

def send_email_via_smtp(message, destination_email)
Net::SMTP.start('smtp.gmail.com', 587, 'localhost.localdomain',
USERNAME, PASSWORD, 'plain') do |smtp|
smtp.send_message(message, EMAIL_ADDR_THAT_SENDS_EM,
destination_email)
end

When I run the app the first line of the above method is causing this
exception to be thrown:

C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:954:in `check_auth_response': 530
5.7.0 Mu
st issue a STARTTLS command first. r36sm4454744qcs.39
(Net::SMTPAuthenticationEr
ror)
from C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:731:in `auth_plain'
from C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:723:in `authenticate'
from C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:566:in `do_start'
from C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
from C:/Ruby192/lib/ruby/1.9.1/net/smtp.rb:463:in `start'
from C:/Program Files/EmailOMatic/src/emailer.rb:36:in
`send_email_via_s
mtp'

Any thoughts to why this change is breaking my code?

Thanks for your assistance,
Alex
 
A

Alex Baranosky

I've been digging around in the source code.

I found I need to call smtp.enable_starttls to get the starttls enabled.

Here's my now working code from above:

def send_email_via_smtp(message, destination_email)
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls
smtp.start('localhost.localdomain', USERNAME, PASSWORD, 'plain') do
|connection|
connection.send_message(message, EMAIL_ADDR_THAT_SENDS_EM,
destination_email)
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top