feat(cli): add command to test emails send correctly
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
65
lib/mix/tasks/mobilizon/maintenance/test_emails.ex
Normal file
65
lib/mix/tasks/mobilizon/maintenance/test_emails.ex
Normal 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
|
||||
@@ -132,4 +132,24 @@ defmodule Mobilizon.Web.Email.Admin do
|
||||
offer_unsupscription: false
|
||||
})
|
||||
end
|
||||
|
||||
@spec email_configuration_test(String.t(), Keyword.t()) :: Swoosh.Email.t()
|
||||
def email_configuration_test(email, options) do
|
||||
locale = Keyword.get(options, :locale, "en")
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"Email configuration test for %{instance}",
|
||||
instance: Config.instance_name()
|
||||
)
|
||||
|
||||
[to: email, subject: subject]
|
||||
|> Email.base_email()
|
||||
|> render_body(:email_configuration_test, %{
|
||||
locale: locale,
|
||||
subject: subject,
|
||||
offer_unsupscription: false
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
60
lib/web/templates/email/email_configuration_test.html.heex
Normal file
60
lib/web/templates/email/email_configuration_test.html.heex
Normal file
@@ -0,0 +1,60 @@
|
||||
<!-- HERO -->
|
||||
<tr>
|
||||
<td bgcolor="#474467" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||
<tr>
|
||||
<td
|
||||
bgcolor="#ffffff"
|
||||
align="center"
|
||||
valign="top"
|
||||
style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #3A384C; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;"
|
||||
>
|
||||
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
|
||||
<%= gettext("Well done!") %>
|
||||
</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
<!-- COPY BLOCK -->
|
||||
<tr>
|
||||
<td bgcolor="#E6E4F4" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td
|
||||
bgcolor="#ffffff"
|
||||
align="left"
|
||||
style="padding: 20px 30px 30px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"
|
||||
>
|
||||
<p style="margin: 0;">
|
||||
<%= gettext(
|
||||
"If you received this email, the email configuration seems to be correct."
|
||||
) %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
@@ -0,0 +1,3 @@
|
||||
<%= gettext "Well done!" %>
|
||||
==
|
||||
<%= gettext "If you received this email, the email configuration seems to be correct." %>
|
||||
Reference in New Issue
Block a user