I’ve just released RhizMail 0.1.0. RhizMail is a test-friendly library for sending out customized emails. This is the library we use day-to-day at rhizome.org, where we send out more than 100 customized emails a day.
To use RhizMail, create an email and deliver it.
def send_site_message( to_address, to_name, body ) msg = RhizMail::Message.new( 'New features at website.com', to_address, 'firstname.lastname@example.org', body ) msg.to_name = to_name msg.deliver end
If you want to test this message, you can set the MockMailer to take place of the default Mailer:
def test_send_site_message mock_mailer = RhizMail::MockMailer.new RhizMail::set_mailer mock_mailer send_site_message( 'email@example.com', 'Bill Smith', 'Hi, Bill!' ) assert_equal( 1, mock_mailer.messages_sent ) assert_equal( 'Bill Smith', mock_mailer.messages_sent.first.to_name ) end
Basically, this means that you can send out as many emails as you want in any part of your code, without having to worry that running a test case will actually send out real emails. (Is there somebody who really has the email address with ‘firstname.lastname@example.org’? If so, it’d be nice not to annoy him.)