1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserEmail do
6 @moduledoc "User emails"
10 alias Pleroma.Web.Endpoint
11 alias Pleroma.Web.Router
13 defp instance_config, do: Pleroma.Config.get(:instance)
15 defp instance_name, do: instance_config()[:name]
18 {instance_name(), instance_config()[:email]}
21 defp recipient(email, nil), do: email
22 defp recipient(email, name), do: {name, email}
23 defp recipient(%Pleroma.User{} = user), do: recipient(user.email, user.name)
25 def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do
27 Router.Helpers.util_url(
34 <h3>Reset your password at #{instance_name()}</h3>
35 <p>Someone has requested password change for your account at #{instance_name()}.</p>
36 <p>If it was you, visit the following link to proceed: <a href="#{password_reset_url}">reset password</a>.</p>
37 <p>If it was someone else, nothing to worry about: your data is secure and your password has not been changed.</p>
41 |> to(recipient(user))
43 |> subject("Password reset")
44 |> html_body(html_body)
47 def user_invitation_email(
49 %Pleroma.UserInviteToken{} = user_invite_token,
54 Router.Helpers.redirect_url(
57 user_invite_token.token
61 <h3>You are invited to #{instance_name()}</h3>
62 <p>#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.</p>
63 <p>Click the following link to register: <a href="#{registration_url}">accept invitation</a>.</p>
67 |> to(recipient(to_email, to_name))
69 |> subject("Invitation to #{instance_name()}")
70 |> html_body(html_body)
73 def account_confirmation_email(user) do
75 Router.Helpers.confirm_email_url(
79 to_string(user.info.confirmation_token)
83 <h3>Welcome to #{instance_name()}!</h3>
84 <p>Email confirmation is required to activate the account.</p>
85 <p>Click the following link to proceed: <a href="#{confirmation_url}">activate your account</a>.</p>
89 |> to(recipient(user))
91 |> subject("#{instance_name()} account confirmation")
92 |> html_body(html_body)