Elixir mailgun错误:IO.chardata_to_string / 1中没有匹配的函数子句

时间:2015-12-02 15:53:23

标签: elixir phoenix-framework elixir-framework

当我尝试通过mailgun库发送电子邮件时,我收到错误:** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1

我在测试中捕获了问题:

测试/邮寄者/ mailer_test.ex

defmodule Myapp.MailerTest do
  use Myapp.ModelCase

  test "mailer test" do
    Myapp.Mailer.invitation_email("abc.com", "foo@bar.com")
  end
end

LIB / mailer.ex

defmodule Myapp.Mailer do
  use Mailgun.Client, domain: "abc.mailgun.org",
                      key: "key-abc",
                      mode: :test,
                      mailgun_test_file_path: "mail.json"

  def invitation_email(host, to_email) do
    send_email to: to_email,
               from: "hi@#{host}",
               subject: "Invitation!",
               html: "<strong>Welcome</strong>"
  end
end

测试运行:

$ mix test test/mailers/mailer_test.ex                                                                                                     
Compiled lib/mailer.ex
Generated myapp app

  1) test mailer test (Myapp.MailerTest)
     test/mailers/mailer_test.ex:4
     ** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
     stacktrace:
       (elixir) lib/io.ex:333: IO.chardata_to_string(nil)
       (elixir) lib/file.ex:701: File.write/3
       lib/client.ex:22: Mailgun.Client.do_send_email/3
       test/mailers/mailer_test.ex:5

Finished in 0.2 seconds (0.1s on load, 0.01s on tests)
1 test, 1 failure

Randomized with seed 182269

另外,顺便提一下,如果删除mode参数,错误就会消失。但它也不会发送电子邮件。

1 个答案:

答案 0 :(得分:2)

mailgun_test_file_path: "mail.json"

应该是:

test_file_path: "mail.json"

https://github.com/chrismccord/mailgun#test-mode