# SMTP with Gmail in 1.9.2

**URL:** <https://www.ruby-forum.com/t/smtp-with-gmail-in-1-9-2/195591>\
**Category:** Ruby\
**Created:** [September 26, 2010, 4:33am UTC](https://www.ruby-forum.com/t/smtp-with-gmail-in-1-9-2/195591 "2010-09-26T04:33:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trib4lmaniac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de053/32.png) [@trib4lmaniac](https://www.ruby-forum.com/u/trib4lmaniac)\
**Post date:** [September 26, 2010, 4:33am UTC](https://www.ruby-forum.com/t/smtp-with-gmail-in-1-9-2/195591/1 "2010-09-26T04:33:24Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![trib4lmaniac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de053/32.png) [@trib4lmaniac](https://www.ruby-forum.com/u/trib4lmaniac)\
**Post date:** [September 26, 2010, 9:03pm UTC](https://www.ruby-forum.com/t/smtp-with-gmail-in-1-9-2/195591/2 "2010-09-26T21:03:43Z")

</div>

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](http://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
