Receiving Email with ActionMailer

This really was a snap.

A nice and simple testing recipe (#68) demonstrates how to read in an email from a fixture in just a few lines and pass them to your processing method (MailReceiver.receive in this case).

def read_fixture(action)
IO.readlines(“#{FIXTURES_PATH}/mail_receiver/#{action}”)
end

def test_something
email = read_fixture(“junk_mail”).join
MailReceiver.receive(email)

# assertions
end

And then a few lines on how to feed it “for real”. and we’re up and running!

The only catch… there was some anger over the parens:

mailman: "|/path/to/app/script/runner Mailman.receive(STDIN.read)"

We ended up escaping them, but according to those directions I just linked to – you can also just quote the call to receive.


		
Advertisements

Leave a comment

Filed under Email, rails, Ruby, Test Driven Development (TDD)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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