我正试图在我的凤凰应用程序中创建一个邮件。我已经走得很远,但现在我正试图从iex控制台发送测试邮件,我收到以下错误:
iex(2)> Radios.Mailer.my_first_email("myemail@domain.com")
{:error, 400,
"{\n \"message\": \"'to' parameter is not a valid address. please check documentation\"\n}"}
mailer.ex
defmodule Radios.Mailer do
use Mailgun.Client,
domain: Application.get_env(:radios, :mailgun_domain),
key: Application.get_env(:radios, :mailgun_key)
def my_first_email(email_address) do
send_email to: "email_address", #<= this appears to be the issue
from: "test@example.com",
subject: "My first email",
text: "This is an email send with Phoenix and Mailgun"
end
end
config.exs
config :radios,
ecto_repos: [Radios.Repo],
mailgun_domain: "https://api.mailgun.net/v3/XXXXXXXXX.mailgun.org",
mailgun_key: "pubkey-XXXXXXXX"
我一直在把双引号更改为单引号,send_email(to: :email_address)
并且还在那里添加了我自己的实际地址。
一切都没有快乐。
我错过了什么?
更新 已将 config.exs 更改为以下内容:
config :radios, Radios.Mailer,
mailgun_domain: "https://api.mailgun.net/v3/XXXXXXXX.mailgun.org",
mailgun_key: "pubkey-XXXXXX"
但现在收到:
iex(1)> Radios.Mailer.my_first_email("myemail@domain.com")
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir) lib/io.ex:445: IO.chardata_to_string(nil)
(elixir) lib/path.ex:468: Path.join/2
(elixir) lib/path.ex:450: Path.join/1
lib/client.ex:44: Mailgun.Client.send_without_attachments/2
答案 0 :(得分:1)
有两个错误:
email_address
是一个变量,但您将字符串"email_address"
传递给to
的{{1}}参数。这样:
send_email
应该是:
send_email to: "email_address",
您从env获取了错误的设置。设置存储在关键字列表send_email to: email_address,
中。
此:
Application.get_env(:radios, Radios.Mailer)
应该是:
use Mailgun.Client,
domain: Application.get_env(:radios, :mailgun_domain),
key: Application.get_env(:radios, :mailgun_key)