Ruby script to send email to multiple recipients by Gmail

This works:

require ‘mail’

#Set up Gmail access
options = { :address => “”,
:port => 587,
:domain => ‘localhost’,
:user_name => ‘’,
:password => ‘passphrase’,
:authentication => ‘plain’,
:enable_starttls_auto => true }

Mail.defaults do
delivery_method :smtp, options

#import email addresses from text file
recips = []
IO.foreach(“test.txt”) do |line|
recips << line

#Status update
puts “Done with readin\n”

#Format email addresses properly with double quotes and send
recips.each {|value|
puts value
baseadd = value.chomp
address = “\””+baseadd+”\””
mail = do
to address
from ‘’
subject ‘A test email’


Leave a Reply

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

You are commenting using your 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: