How To : Send emails via Gmail SMTP in Ruby

Here is a simple ruby code to send emails through Gmail SMTP servers.  This code uses the Mail gem available @ https://github.com/mikel/mail

require 'mail'

options = { 
            :address              => "smtp.gmail.com",
            :port                 => 587,
            :user_name            => '<gmail user name>@gmail.com',
            :password             => '<gmail password>',
            :authentication       => 'plain',
            :enable_starttls_auto => true  

Mail.defaults do
  delivery_method :smtp, options

Mail.deliver do
       to '<email of receiver>'
     from '<gmail user name>@gmail.com'
  subject 'Subject - Ruby Email via Gmail SMTP'
     body 'sample content sample content sample content '

Please do post your queries and suggestions in the comments section below.

1 comment:

  1. Slot Machines in Oklahoma - Mapkiwis.com
    The casino is located near the historic Ak-Chin 스포츠벳 Indian Nation's Indian 윌리엄 힐 reservations 넥스트 벳 in Oklahoma City, a major 먹튀 커뮤니티 thoroughfare 188bet that runs from Harrah's Resort