summaryrefslogtreecommitdiff
path: root/lib/mix/tasks/pleroma/email.ex
blob: c0bef03861c96d2a4e596764af13af9eea6a18cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
defmodule Mix.Tasks.Pleroma.Email do
  use Mix.Task
  import Mix.Pleroma

  @shortdoc "Email administrative tasks"
  @moduledoc File.read!("docs/administration/CLI_tasks/email.md")

  def run(["test" | args]) do
    Mix.Pleroma.start_pleroma()

    {options, [], []} =
      OptionParser.parse(
        args,
        strict: [
          to: :string
        ]
      )

    email = Pleroma.Emails.AdminEmail.test_email(options[:to])
    {:ok, _} = Pleroma.Emails.Mailer.deliver(email)

    shell_info("Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}")
  end

  def run(["resend_confirmation_emails"]) do
    start_pleroma()

    Pleroma.User.Query.build(%{
      local: true,
      deactivated: false,
      confirmation_pending: true,
      invisible: false
    })
    |> Pleroma.RepoStreamer.chunk_stream(500)
    |> Stream.each(fn users ->
      users
      |> Enum.each(fn user -> Pleroma.User.try_send_confirmation_email(user) end)
    end)
    |> Stream.run()
  end
end