6b7555fb81630dea18adaf7d786099ae3f8956ab
[akkoma] / lib / mix / tasks / pleroma / email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.Email do
6 use Mix.Task
7 import Mix.Pleroma
8
9 @shortdoc "Email administrative tasks"
10 @moduledoc File.read!("docs/administration/CLI_tasks/email.md")
11
12 def run(["test" | args]) do
13 start_pleroma()
14
15 {options, [], []} =
16 OptionParser.parse(
17 args,
18 strict: [
19 to: :string
20 ]
21 )
22
23 email = Pleroma.Emails.AdminEmail.test_email(options[:to])
24 {:ok, _} = Pleroma.Emails.Mailer.deliver(email)
25
26 shell_info("Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}")
27 end
28
29 def run(["resend_confirmation_emails"]) do
30 start_pleroma()
31
32 shell_info("Sending emails to all unconfirmed users")
33
34 Pleroma.User.Query.build(%{
35 local: true,
36 deactivated: false,
37 is_confirmed: false,
38 invisible: false
39 })
40 |> Pleroma.Repo.chunk_stream(500)
41 |> Stream.each(&Pleroma.User.try_send_confirmation_email(&1))
42 |> Stream.run()
43 end
44 end