jeudi 27 avril 2017

How do I test ActionMailer receive method with attachments in local development?

I'm writing an application that will receive emails forwarded by postfix to the rails app, and the app should behave differently if an email has or hasn't attachments.

I saw this in this stackoverflow post and it seems fine to test receiving emails. But I need to test attachments too, how could I do that?

require 'test_helper'
class ReceiverTest < ActionMailer::TestCase


test "parse incoming mail" do
    email = TMail::Mail.parse(File.open("test/fixtures/emails/example1.txt",'r').read)
    assert_difference "ProcessedMail.count" do
      Receiver.receive email
    end
  end

And finally, would I need to install and configure postfix to try the app locally and check if all goes well or do Rails provide another method to do that and leave that configuration for production server?

Aucun commentaire:

Enregistrer un commentaire