Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 在混合任务中使用竹子发送电子邮件_Elixir_Phoenix Framework - Fatal编程技术网

Elixir 在混合任务中使用竹子发送电子邮件

Elixir 在混合任务中使用竹子发送电子邮件,elixir,phoenix-framework,Elixir,Phoenix Framework,我想发送一封来自混合任务的电子邮件。以下是任务的代码: defmodule Mix.Tasks.sendmails.rementer do 使用Mix.Task 进口混合 导入外部查询 def运行(_参数)do Foobar.welcome|u email |>MyApp.Mailer.deliver|u立即发送 结束 结束 德福巴多模块 进口竹子。电邮 欢迎你发电子邮件 新邮件 |>到(”foo@example.com") |>从(”me@example.com") |>主题(“欢迎!!!”)

我想发送一封来自混合任务的电子邮件。以下是任务的代码:

defmodule Mix.Tasks.sendmails.rementer do
使用Mix.Task
进口混合
导入外部查询
def运行(_参数)do
Foobar.welcome|u email |>MyApp.Mailer.deliver|u立即发送
结束
结束
德福巴多模块
进口竹子。电邮
欢迎你发电子邮件
新邮件
|>到(”foo@example.com")
|>从(”me@example.com")
|>主题(“欢迎!!!”)
|>html_body(“欢迎””)
|>正文(“欢迎”)
结束
结束
运行此混合任务时,我会得到以下日志输出:

21:20:26.829 [debug] Sending email with Bamboo.LocalAdapter:

%Bamboo.Email{assigns: %{}, bcc: [], cc: [], from: {nil, 
"me@example.com"}, headers: %{}, html_body: "<strong>Welcome</strong>",
private: %{}, subject: "Welcome!!!", text_body: "welcome", to: 
[nil: "foo@example.com"]}

** (exit) exited in: GenServer.call(Bamboo.SentEmail, {:update, 
    #Function<2.18788267/1 in Bamboo.SentEmail.push/1>}, 5000)
    ** (EXIT) no process: the process is not alive or there's no 
    process currently associated with the given name, possibly 
    because its application isn't started
    (elixir) lib/gen_server.ex:729: GenServer.call/3
    lib/bamboo/sent_email.ex:109: Bamboo.SentEmail.push/1
    lib/bamboo/mailer.ex:121: Bamboo.Mailer.deliver_now/3
    lib/mix/tasks/send_emails.reminder.ex:30: anonymous fn/2 in Mix.Tasks.SendEmails.Reminder.run/1
    (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/mix/tasks/send_emails.reminder.ex:20: Mix.Tasks.SendEmails.Reminder.run/1
    (mix) lib/mix/task.ex:294: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
    (elixir) lib/code.ex:370: Code.require_file/2
21:20:26.829[debug]使用bambol.LocalAdapter发送电子邮件:
%电子邮件{分配:%{},密件抄送:[],抄送:[],发件人:{nil,
"me@example.com},标题:%{},html_正文:“欢迎”,
私人:%{},主题:“欢迎!!!”,正文:“欢迎”,收件人:
[无:]foo@example.com"]}
**(退出)退出:GenServer.call(bambor.sentmail,{:update,
#函数},5000)
**(退出)无进程:进程不活动或没有
当前与给定名称关联的进程,可能是
因为它的应用程序还没有启动
(elixir)lib/gen_server.ex:729:GenServer.call/3
lib/bambon/sent_email.ex:109:bambon.sentmail.push/1
lib/bambon/mailer.ex:121:bambon.mailer.delivery_now/3
lib/mix/tasks/send_emails.remention.ex:30:mix.tasks.sendmails.remention.run/1中的匿名fn/2
(elixir)lib/enum.ex:1755:enum。“-reduce/3-lists^foldl/2-0-”/3
lib/mix/tasks/send_emails.remention.ex:20:mix.tasks.sendmails.remention.run/1
(mix)lib/mix/task.ex:294:mix.task.run_task/3
(mix)lib/mix/cli.ex:58:mix.cli.run_task/2
(elixir)lib/code.ex:370:code.require\u文件/2

我怎样才能解决这个问题?竹子在凤凰应用程序中效果很好。我只是无法在混合任务中运行它。

发生此错误是因为未启动
bambol

启动单个应用程序 在您的情况下,用于启动特定应用程序:

Application.ensure_all_started(:bamboo)
启动所有应用程序 在某些情况下,您可能希望启动所有应用程序: 将启动在
mix.exs
config中定义的所有应用程序:

defmodule Mix.Tasks.SendEmails.Reminder do
  use Mix.Task
  import Mix.Ecto
  import Ecto.Query

  def run(_args) do
    Mix.Tasks.App.Start.run([]) # This will start all apps
    Foobar.welcome_email |> MyApp.Mailer.deliver_now
  end
end

应用程序。确保所有已启动(:bambol)
在这种情况下是更好的解决方案,因为您不会启动整个应用程序,只启动所需的依赖项。@PatNowak True,编辑了答案,
应用程序。确保\u all \u started
现在是主要解决方案。警告:不应
将Mix.exto
导入为Mix.exto被视为私有API