Saturday, October 02, 2004

Mail merge ruby script

The other day, I needed to send the gmail invite to all the folks in the development team and it amounted to more than 30 people. Since each one would have to be sent a different invite, distribution list won't work. Here is a quick Ruby script I cranked up to send the invites. Go ruby.


require 'net/smtp'

receiver_list = ['x@y.com','a@b.com']
invites_list = ['invite_url_1','invite_url_2']
smtp = Net::SMTP.start('mta1.mycompany.com', 25)
sender = 'me@gmail.com'

receiver_list.each_index {|email_index|
receiver = receiver_list[email_index]
invite_link = invites_list[email_index]
puts "Sending e-mail to " + receiver
msgstr = "From: Venkat <#{sender}>\n"
msgstr += "To: #{receiver} <#{receiver}>\n"
msgstr += "Subject: Gmail invitation\n"
msgstr += "I would like you to enjoy a small gift, a new Gmail account.\n"
msgstr += "#{invite_link}\n\n"
msgstr += "Cheers,\n"
msgstr += "Venkat.\n"
puts smtp.send_mail(msgstr, sender, receiver)
}

2 comments:

Anonymous said...

Hi Venkat,
That's a very neat script for sending out bulk emails. it would be very useful for sending out personalised email invitations or announcements.
--Deepak

Anonymous said...

hai there

i am also trying to use this script , but in my place its not working my server do not support authentication, its like relay only . if u have any other script tell me.

thanks yar

rakesh

rakeshahuja@30gigs.com