Skip to content

Instantly share code, notes, and snippets.

@ebot
Created January 27, 2010 16:28
Show Gist options
  • Save ebot/287973 to your computer and use it in GitHub Desktop.
Save ebot/287973 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'net/smtp'
def send_mail(options = {})
begin
puts "Assembling mail..."
options = {
:smtp_server => '555.55.55.555',
:from => '[email protected]',
:to => '[email protected]',
:subject => 'Ruby Test Mail',
:message => 'Just Testing!'
}.merge options
to = options[:to]
to = to.collect{|a| a + ", "}.to_s.chop.chop if to.instance_of?( Array )
msg = "From: #{options[:from]}\n" <<
"To: #{to}\n" <<
"Subject: #{options[:subject]}\n" <<
"\n" <<
options[:message]
Net::SMTP.start(options[:smtp_server]) do |smtp|
smtp.send_message msg, options[:from], options[:to]
end
puts "...Finished delivering mail."
rescue Exception => e
puts "...#{e.message}"
end
end
message = <<-end
This is a a ruby script testing multiple recepients on an email.
Please reply when you get this and then delete.
-Ed
end
send_mail( {:message => message, :to => ['[email protected]', '[email protected]', '[email protected]'] })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment