mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-25 04:53:06 +00:00
Create pleroma.email mix task
Closes: https://git.pleroma.social/pleroma/pleroma/issues/1061
This commit is contained in:
parent
b12f306473
commit
4eb935be78
|
@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Static Frontend: Add the ability to render user profiles and notices server-side without requiring JS app.
|
||||
- Mix task to re-count statuses for all users (`mix pleroma.count_statuses`)
|
||||
- Mix task to list all users (`mix pleroma.user list`)
|
||||
- Mix task to send a test email (`mix pleroma.email test`)
|
||||
- Support for `X-Forwarded-For` and similar HTTP headers which used by reverse proxies to pass a real user IP address to the backend. Must not be enabled unless your instance is behind at least one reverse proxy (such as Nginx, Apache HTTPD or Varnish Cache).
|
||||
- MRF: New module which handles incoming posts based on their age. By default, all incoming posts that are older than 2 days will be unlisted and not shown to their followers.
|
||||
- User notification settings: Add `privacy_option` option.
|
||||
|
|
24
docs/administration/CLI_tasks/email.md
Normal file
24
docs/administration/CLI_tasks/email.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Managing emails
|
||||
|
||||
{! backend/administration/CLI_tasks/general_cli_task_info.include !}
|
||||
|
||||
## Send test email (instance email by default)
|
||||
|
||||
```sh tab="OTP"
|
||||
./bin/pleroma_ctl email test [--to <destination email address>]
|
||||
```
|
||||
|
||||
```sh tab="From Source"
|
||||
mix pleroma.email test [--to <destination email address>]
|
||||
```
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
```sh tab="OTP"
|
||||
./bin/pleroma_ctl email test --to root@example.org
|
||||
```
|
||||
|
||||
```sh tab="From Source"
|
||||
mix pleroma.email test --to root@example.org
|
||||
```
|
25
lib/mix/tasks/pleroma/email.ex
Normal file
25
lib/mix/tasks/pleroma/email.ex
Normal file
|
@ -0,0 +1,25 @@
|
|||
defmodule Mix.Tasks.Pleroma.Email do
|
||||
use Mix.Task
|
||||
|
||||
@shortdoc "Simple Email test"
|
||||
@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)
|
||||
|
||||
Mix.shell().info(
|
||||
"Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}"
|
||||
)
|
||||
end
|
||||
end
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Emails.AdminEmail do
|
|||
|
||||
import Swoosh.Email
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.Router.Helpers
|
||||
|
||||
defp instance_config, do: Pleroma.Config.get(:instance)
|
||||
|
@ -20,6 +21,19 @@ defp user_url(user) do
|
|||
Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
|
||||
end
|
||||
|
||||
def test_email(mail_to \\ nil) do
|
||||
html_body = """
|
||||
<h3>Instance Test Email</h3>
|
||||
<p>A test email was requested. Hello. :)</p>
|
||||
"""
|
||||
|
||||
new()
|
||||
|> to(mail_to || Config.get([:instance, :email]))
|
||||
|> from({instance_name(), instance_notify_email()})
|
||||
|> subject("Instance Test Email")
|
||||
|> html_body(html_body)
|
||||
end
|
||||
|
||||
def report(to, reporter, account, statuses, comment) do
|
||||
comment_html =
|
||||
if comment do
|
||||
|
|
52
test/tasks/email_test.exs
Normal file
52
test/tasks/email_test.exs
Normal file
|
@ -0,0 +1,52 @@
|
|||
defmodule Mix.Tasks.Pleroma.EmailTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "pleroma.email test" do
|
||||
test "Sends test email with no given address" do
|
||||
mail_to = Config.get([:instance, :email])
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Email.run(["test"])
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message =~ "Test email has been sent"
|
||||
|
||||
assert_email_sent(
|
||||
to: mail_to,
|
||||
html_body: ~r/a test email was requested./i
|
||||
)
|
||||
end
|
||||
|
||||
test "Sends test email with given address" do
|
||||
mail_to = "hewwo@example.com"
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Email.run(["test", "--to", mail_to])
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message =~ "Test email has been sent"
|
||||
|
||||
assert_email_sent(
|
||||
to: mail_to,
|
||||
html_body: ~r/a test email was requested./i
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue