fix sender for welcome email
This commit is contained in:
parent
b620290dd9
commit
5879d36854
@ -260,7 +260,7 @@ config :pleroma, :welcome,
|
||||
],
|
||||
email: [
|
||||
enabled: false,
|
||||
sender_nickname: nil,
|
||||
sender: nil,
|
||||
subject: "Welcome to <%= instance_name %>",
|
||||
html: "Welcome to <%= instance_name %>",
|
||||
text: "Welcome to <%= instance_name %>"
|
||||
|
@ -990,11 +990,12 @@ config :pleroma, :config_description, [
|
||||
description: "Enables sends direct message for new user after registration"
|
||||
},
|
||||
%{
|
||||
key: :sender_nickname,
|
||||
type: :string,
|
||||
description: "The nickname of the local user that sends the welcome email",
|
||||
key: :sender,
|
||||
type: [:string, :tuple],
|
||||
description:
|
||||
"The email address or tuple with `{nickname, email}` that will use as sender to the welcome email.",
|
||||
suggestions: [
|
||||
"lain"
|
||||
{"Pleroma App", "welcome@pleroma.app"}
|
||||
]
|
||||
},
|
||||
%{
|
||||
|
@ -46,8 +46,6 @@ To add configuration to your config file, you can copy it from the base config.
|
||||
* `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature.
|
||||
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
|
||||
* `attachment_links`: Set to true to enable automatically adding attachment link text to statuses.
|
||||
* `welcome_message`: A message that will be send to a newly registered users as a direct message.
|
||||
* `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
|
||||
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`).
|
||||
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`.
|
||||
* `healthcheck`: If set to true, system data will be shown on ``/api/pleroma/healthcheck``.
|
||||
@ -70,11 +68,29 @@ To add configuration to your config file, you can copy it from the base config.
|
||||
* `message`: A message that will be send to a newly registered users as a direct message.
|
||||
* `email`: - welcome message sent as a email.
|
||||
* `enabled`: Enables the send a welcome email to a newly registered user. Defaults to `false`.
|
||||
* `sender_nickname`: The nickname of the local user that sends the welcome email.
|
||||
* `sender`: The email address or tuple with `{nickname, email}` that will use as sender to the welcome email.
|
||||
* `subject`: A subject of welcome email.
|
||||
* `html`: A html that will be send to a newly registered users as a email.
|
||||
* `text`: A text that will be send to a newly registered users as a email.
|
||||
|
||||
Example:
|
||||
|
||||
```elixir
|
||||
config :pleroma, :welcome,
|
||||
direct_message: [
|
||||
enabled: true,
|
||||
sender_nickname: "lain",
|
||||
message: "Hi, @username! Welcome on board!"
|
||||
],
|
||||
email: [
|
||||
enabled: true,
|
||||
sender: {"Pleroma App", "welcome@pleroma.app"},
|
||||
subject: "Welcome to <%= instance_name %>",
|
||||
html: "Welcome to <%= instance_name %>",
|
||||
text: "Welcome to <%= instance_name %>"
|
||||
]
|
||||
```
|
||||
|
||||
## Message rewrite facility
|
||||
|
||||
### :mrf
|
||||
|
@ -27,7 +27,7 @@ defmodule Pleroma.User.WelcomeEmail do
|
||||
bindings = [user: user, instance_name: instance_name()]
|
||||
|
||||
%{}
|
||||
|> add_sender(Config.get([:welcome, :email, :sender_nickname], nil))
|
||||
|> add_sender(Config.get([:welcome, :email, :sender], nil))
|
||||
|> add_option(:subject, bindings)
|
||||
|> add_option(:html, bindings)
|
||||
|> add_option(:text, bindings)
|
||||
@ -40,28 +40,22 @@ defmodule Pleroma.User.WelcomeEmail do
|
||||
|> merge_options(opts, option)
|
||||
end
|
||||
|
||||
def add_sender(opts, nickname) do
|
||||
nickname
|
||||
|> fetch_sender()
|
||||
|> merge_options(opts, :sender)
|
||||
defp add_sender(opts, {_name, _email} = sender) do
|
||||
merge_options(sender, opts, :sender)
|
||||
end
|
||||
|
||||
defp add_sender(opts, sender) when is_binary(sender) do
|
||||
add_sender(opts, {instance_name(), sender})
|
||||
end
|
||||
|
||||
defp add_sender(opts, _), do: opts
|
||||
|
||||
defp merge_options(nil, options, _option), do: options
|
||||
|
||||
defp merge_options(value, options, option) do
|
||||
Map.merge(options, %{option => value})
|
||||
end
|
||||
|
||||
defp fetch_sender(nickname) when is_binary(nickname) do
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
{instance_name(), user.email}
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_sender(_), do: nil
|
||||
|
||||
defp eval_string(nil, _), do: nil
|
||||
defp eval_string("", _), do: nil
|
||||
defp eval_string(str, bindings), do: EEx.eval_string(str, bindings)
|
||||
|
@ -16,11 +16,10 @@ defmodule Pleroma.User.WelcomeEmailTest do
|
||||
|
||||
describe "send_email/1" do
|
||||
test "send a welcome email" do
|
||||
welcome_user = insert(:user)
|
||||
user = insert(:user, name: "Jimm")
|
||||
|
||||
Config.put([:welcome, :email, :enabled], true)
|
||||
Config.put([:welcome, :email, :sender_nickname], welcome_user.nickname)
|
||||
Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
|
||||
|
||||
Config.put(
|
||||
[:welcome, :email, :subject],
|
||||
@ -39,7 +38,20 @@ defmodule Pleroma.User.WelcomeEmailTest do
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, welcome_user.email},
|
||||
from: {instance_name, "welcome@pleroma.app"},
|
||||
to: {user.name, user.email},
|
||||
subject: "Hello, welcome to pleroma: #{instance_name}",
|
||||
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
||||
)
|
||||
|
||||
Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
|
||||
|
||||
{:ok, _job} = WelcomeEmail.send_email(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma App", "welcome@pleroma.app"},
|
||||
to: {user.name, user.email},
|
||||
subject: "Hello, welcome to pleroma: #{instance_name}",
|
||||
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
||||
|
@ -414,7 +414,7 @@ defmodule Pleroma.UserTest do
|
||||
Pleroma.Config.put([:welcome, :direct_message, :message], "Hello, this is a cool site")
|
||||
|
||||
Pleroma.Config.put([:welcome, :email, :enabled], true)
|
||||
Pleroma.Config.put([:welcome, :email, :sender_nickname], welcome_user.nickname)
|
||||
Pleroma.Config.put([:welcome, :email, :sender], welcome_user.email)
|
||||
|
||||
Pleroma.Config.put(
|
||||
[:welcome, :email, :subject],
|
||||
|
Loading…
Reference in New Issue
Block a user