DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Simple "Send Email From Ruby" Method

08.03.2006
| 54521 views |
  • submit to reddit
        By Ian Purton and found at <a href="http://jiploo.com/blog/simple-email-send-function-in-ruby/">http://jiploo.com/blog/simple-email-send-function-in-ruby/</a>

def send_email(from, from_alias, to, to_alias, subject, message)
	msg = <<END_OF_MESSAGE
From: #{from_alias} <#{from}>
To: #{to_alias} <#{to}>
Subject: #{subject}
	
#{message}
END_OF_MESSAGE
	
	Net::SMTP.start('localhost') do |smtp|
		smtp.send_message msg, from, to
	end
end
    

Comments

Snippets Manager replied on Fri, 2010/01/29 - 4:13am

If you're looking for something a little more robust, and don't mind installing a ruby gem, I'd recommend pony (http://github.com/benprew/pony). It supposed smtp, tls and can even send email using the local sendmail binary!