Update email settings, add email tester
This commit is contained in:
parent
401009bfdb
commit
88f5c52c50
7 changed files with 64 additions and 4 deletions
|
@ -21,7 +21,8 @@ if System.get_env("PHX_SERVER") do
|
||||||
end
|
end
|
||||||
|
|
||||||
config :comfycamp,
|
config :comfycamp,
|
||||||
jwt_secret: System.get_env("JWT_SECRET")
|
jwt_secret: System.get_env("JWT_SECRET"),
|
||||||
|
smtp_from: System.get_env("SMTP_FROM") || "admin@comfycamp.space"
|
||||||
|
|
||||||
if config_env() == :prod do
|
if config_env() == :prod do
|
||||||
database_url =
|
database_url =
|
||||||
|
@ -108,8 +109,8 @@ if config_env() == :prod do
|
||||||
relay: System.get_env("SMTP_RELAY"),
|
relay: System.get_env("SMTP_RELAY"),
|
||||||
username: System.get_env("SMTP_USERNAME"),
|
username: System.get_env("SMTP_USERNAME"),
|
||||||
password: System.get_env("SMTP_PASSWORD"),
|
password: System.get_env("SMTP_PASSWORD"),
|
||||||
ssl: System.get_env("SMTP_SSL") == "true",
|
ssl: true,
|
||||||
tls: :if_available,
|
tls: :always,
|
||||||
auth: :always,
|
auth: :always,
|
||||||
port: Integer.parse(System.get_env("SMTP_PORT") || "465")
|
port: Integer.parse(System.get_env("SMTP_PORT") || "465")
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule Comfycamp.Accounts.UserNotifier do
|
||||||
email =
|
email =
|
||||||
new()
|
new()
|
||||||
|> to(recipient)
|
|> to(recipient)
|
||||||
|> from({"Comfycamp", "contact@example.com"})
|
|> from({"Comfycamp", Application.fetch_env!(:comfycamp, :smtp_from)})
|
||||||
|> subject(subject)
|
|> subject(subject)
|
||||||
|> text_body(body)
|
|> text_body(body)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,27 @@
|
||||||
defmodule Comfycamp.Mailer do
|
defmodule Comfycamp.Mailer do
|
||||||
use Swoosh.Mailer, otp_app: :comfycamp
|
use Swoosh.Mailer, otp_app: :comfycamp
|
||||||
|
|
||||||
|
alias Swoosh.Email
|
||||||
|
alias Comfycamp.Mailer
|
||||||
|
|
||||||
|
def send_test_email(addr) do
|
||||||
|
email =
|
||||||
|
Email.new()
|
||||||
|
|> Email.to(addr)
|
||||||
|
|> Email.from({"Comfycamp", Application.fetch_env!(:comfycamp, :smtp_from)})
|
||||||
|
|> Email.subject("Test email")
|
||||||
|
|> Email.text_body("""
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Hi,
|
||||||
|
|
||||||
|
Email is working fine!
|
||||||
|
|
||||||
|
==============================
|
||||||
|
""")
|
||||||
|
|
||||||
|
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||||
|
{:ok, email}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
OpenID
|
OpenID
|
||||||
</.link>
|
</.link>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<.link href={~p"/admin/email"}>
|
||||||
|
Email
|
||||||
|
</.link>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<%= @inner_content %>
|
<%= @inner_content %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,4 +20,18 @@ defmodule ComfycampWeb.AdminPageController do
|
||||||
|> put_layout(html: :admin)
|
|> put_layout(html: :admin)
|
||||||
|> render(:home, page_title: "Админка")
|
|> render(:home, page_title: "Админка")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_overview(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_layout(html: :admin)
|
||||||
|
|> render(:email_overview, page_title: "Email - Админка")
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_email(conn, %{"addr" => addr}) do
|
||||||
|
Comfycamp.Mailer.send_test_email(addr)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Письмо отправлено")
|
||||||
|
|> redirect(to: ~p"/admin/email")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,4 +30,16 @@ defmodule ComfycampWeb.AdminPageHTML do
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_overview(assigns) do
|
||||||
|
~H"""
|
||||||
|
<div>
|
||||||
|
<.header>Проверка email</.header>
|
||||||
|
<.form for={nil} action={~p"/admin/send_email"} method="POST">
|
||||||
|
<.input label="Тестовый адрес" name="addr" value="" type="email" />
|
||||||
|
<.button type="submit">Отправить</.button>
|
||||||
|
</.form>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,6 +114,10 @@ defmodule ComfycampWeb.Router do
|
||||||
|
|
||||||
get "/", AdminPageController, :home
|
get "/", AdminPageController, :home
|
||||||
get "/services", AdminPageController, :services
|
get "/services", AdminPageController, :services
|
||||||
|
|
||||||
|
get "/email", AdminPageController, :email_overview
|
||||||
|
post "/send_email", AdminPageController, :send_email
|
||||||
|
|
||||||
resources "/notes", NotesEditorController
|
resources "/notes", NotesEditorController
|
||||||
resources "/users", UserEditorController, only: [:index, :show]
|
resources "/users", UserEditorController, only: [:index, :show]
|
||||||
resources "/oidc_apps", OIDCAppController
|
resources "/oidc_apps", OIDCAppController
|
||||||
|
|
Loading…
Reference in a new issue