add admin mailer

This commit is contained in:
Tao Bror Bojlén 2019-07-25 18:13:03 +03:00
parent 743dd2f192
commit 8530fe7d3b
No known key found for this signature in database
GPG Key ID: C6EC7AAB905F9E6F
4 changed files with 27 additions and 1 deletions

View File

@ -31,4 +31,9 @@ config :ex_twilio,
config :backend, :crawler,
admin_phone: System.get_env("ADMIN_PHONE"),
twilio_phone: System.get_env("TWILIO_PHONE")
twilio_phone: System.get_env("TWILIO_PHONE"),
admin_email: System.get_env("ADMIN_EMAIL")
config :backend, Backend.Mailer,
adapter: Swoosh.Adapters.Sendgrid,
api_key: System.get_env("SENDGRID_API_KEY")

View File

@ -204,6 +204,7 @@ defmodule Backend.Scheduler do
Logger.info(message)
send_admin_sms(message)
Backend.Mailer.AdminEmail.send("Potential spam", message)
else
Logger.debug("Did not find potential spam instances.")
end

View File

@ -0,0 +1,17 @@
defmodule Backend.Mailer.AdminEmail do
import Swoosh.Email
import Backend.Util
def send(subject, body) do
admin_email = get_config(:admin_email)
if admin_email != nil do
new()
|> to(admin_email)
|> from("noreply@fediverse.space")
|> subject(subject)
|> text_body(body)
|> Backend.Mailer.deliver!()
end
end
end

View File

@ -0,0 +1,3 @@
defmodule Backend.Mailer do
use Swoosh.Mailer, otp_app: :backend
end