feat(cli): add command to test emails send correctly

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-12-06 18:56:46 +01:00
parent 4855af8f87
commit 7210f86889
62 changed files with 1478 additions and 786 deletions

View File

@@ -0,0 +1,65 @@
defmodule Mix.Tasks.Mobilizon.Maintenance.TestEmails do
@moduledoc """
Task to send an email to check if the configuration is running properly
"""
use Mix.Task
import Mix.Tasks.Mobilizon.Common
alias Mobilizon.Config
alias Mobilizon.Web.Email
@shortdoc "Send an email to check if the configuration is running properly"
@impl Mix.Task
def run(options) do
{options, args, []} =
OptionParser.parse(
options,
strict: [
locale: :string,
help: :boolean
],
aliases: [
l: :locale,
h: :help
]
)
if Keyword.get(options, :help, false) do
show_help()
end
if Enum.empty?(args) do
shell_error("mobilizon.maintenance.test_emails requires an email as argument")
end
start_mobilizon()
default_language = Config.default_language()
args
|> hd()
|> String.trim()
|> Email.Admin.email_configuration_test(
locale: Keyword.get(options, :locale, default_language)
)
|> Email.Mailer.send_email()
end
defp show_help do
shell_info("""
mobilizon.maintenance.test_emails [-h/--help] [email]
This command allows to send an email to an address in order to verify if email works
Options:
-l/--locale
Locale for the mail message (en_US, de_DE, …)
-h/--help
Show the help
""")
shutdown(error_code: 0)
end
end