After digging through countless posts trying to find a quick and easy way to send Gmail using Ruby, I eventually had to come up with something on my own. Most solutions online require installing Gmail-specific gems (unnecessary) or are based on versions of Ruby prior to 1.8.7, which added native TLS support to Net::SMTP
. The following code is based on a great little method by Jerod Santo, but has been expanded to work with Gmail and Net::SMTP
's native TLS support:
require 'net/smtp'
def send_gmail(to,opts={})
opts[:server] ||='smtp.gmail.com'
opts[:port] ||= 587
opts[:from_dom] ||='<your_domain>'
opts[:login] ||='<your_login>'
opts[:pass] ||=''