Handle possibility of user account in a bulk operation not having an email address
[akkoma] / lib / mix / tasks / pleroma / email.ex
1 defmodule Mix.Tasks.Pleroma.Email do
2 use Mix.Task
3 import Mix.Pleroma
4
5 @shortdoc "Email administrative tasks"
6 @moduledoc File.read!("docs/administration/CLI_tasks/email.md")
7
8 def run(["test" | args]) do
9 Mix.Pleroma.start_pleroma()
10
11 {options, [], []} =
12 OptionParser.parse(
13 args,
14 strict: [
15 to: :string
16 ]
17 )
18
19 email = Pleroma.Emails.AdminEmail.test_email(options[:to])
20 {:ok, _} = Pleroma.Emails.Mailer.deliver(email)
21
22 shell_info("Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}")
23 end
24
25 def run(["resend_confirmation_emails"]) do
26 start_pleroma()
27
28 Pleroma.User.Query.build(%{
29 local: true,
30 deactivated: false,
31 confirmation_pending: true,
32 invisible: false
33 })
34 |> Pleroma.RepoStreamer.chunk_stream(500)
35 |> Stream.each(fn users ->
36 users
37 |> Enum.each(fn user -> Pleroma.User.try_send_confirmation_email(user) end)
38 end)
39 |> Stream.run()
40 end
41 end