Send Gmail From Ruby Script

Hi.

Now we are going to see , how to send e-mail from Ruby Script.

fro that we need to install ,

$ sudo apt-get install ruby

$ sudo apt-get install rubygems

$ sudo gem install tlsmail

gmail.rb

require ‘rubygems’
require ‘tlsmail’
require ‘time’

$a=[‘tarulalan@gmail.com’,’tshrinivasan@gmail.com’,’jemenisuresh@gmail.com’]
$a.each do |to_mail|

content = <<MESSAGE_END
From: Arulalan <tarulalan@gmail.com>
To: #{to_mail}
Subject: SMTP e-mail test

This is a test e-mail message….

hi da.. how r u .. i m fine… now i sending this mail from ruby scrpt…… This body of our mail

MESSAGE_END

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start(‘smtp.gmail.com’, 587, ‘gmail.com’, ‘tarulalan@gmail.com’, ‘my passwd’, :login) do |smtp|
smtp.send_message(content, ‘tarulalan@gmail.com’, “#{to_mail}”)
end

end

# End Of Program

in this Prog , $a is an array and u can add many email id  to send mail.

and in this program tarulalan@gmail is my mail id.. you can replace with ur  gmail id.  🙂

அருளாளன் . த

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: