make ADMIN_EMAIL optional
This commit is contained in:
parent
66091b4f9e
commit
f8293bc618
16
.env.example
16
.env.example
|
@ -4,18 +4,22 @@ URL=http://localhost:7777
|
||||||
# If you want to enable sentry for error tracking, put your sentry dsn here.
|
# If you want to enable sentry for error tracking, put your sentry dsn here.
|
||||||
# SENTRY_DSN=your_sentry_dsn
|
# SENTRY_DSN=your_sentry_dsn
|
||||||
|
|
||||||
# apply colored log
|
# apply colored log to facilitate local development
|
||||||
COLOR_LOG=true
|
# COLOR_LOG=true
|
||||||
|
|
||||||
# <<< Email related settings >>>
|
# <<< Email related settings >>>
|
||||||
# Only print email content, not sending it
|
# Only print email content, not sending it, for local development
|
||||||
NOT_SEND_EMAIL=true
|
# NOT_SEND_EMAIL=true
|
||||||
|
|
||||||
# domain used to create alias
|
# domain used to create alias
|
||||||
EMAIL_DOMAIN=sl.local
|
EMAIL_DOMAIN=sl.local
|
||||||
|
|
||||||
# transactional email is sent from this email address
|
# transactional email is sent from this email address
|
||||||
SUPPORT_EMAIL=support@sl.local
|
SUPPORT_EMAIL=support@sl.local
|
||||||
# to send general stats
|
|
||||||
ADMIN_EMAIL=admin@sl.local
|
# to receive general stats.
|
||||||
|
# ADMIN_EMAIL=admin@sl.local
|
||||||
|
|
||||||
# Max number emails user can generate for free plan
|
# Max number emails user can generate for free plan
|
||||||
MAX_NB_EMAIL_FREE_PLAN=3
|
MAX_NB_EMAIL_FREE_PLAN=3
|
||||||
# custom domain needs to point to these MX servers
|
# custom domain needs to point to these MX servers
|
||||||
|
|
|
@ -40,7 +40,7 @@ SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||||
NOT_SEND_EMAIL = "NOT_SEND_EMAIL" in os.environ
|
NOT_SEND_EMAIL = "NOT_SEND_EMAIL" in os.environ
|
||||||
EMAIL_DOMAIN = os.environ["EMAIL_DOMAIN"]
|
EMAIL_DOMAIN = os.environ["EMAIL_DOMAIN"]
|
||||||
SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"]
|
SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"]
|
||||||
ADMIN_EMAIL = os.environ["ADMIN_EMAIL"]
|
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL")
|
||||||
MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"])
|
MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"])
|
||||||
# allow to override postfix server locally
|
# allow to override postfix server locally
|
||||||
POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "1.1.1.1")
|
POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "1.1.1.1")
|
||||||
|
|
|
@ -5,13 +5,7 @@ from smtplib import SMTP
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
from app.config import (
|
from app.config import SUPPORT_EMAIL, ROOT_DIR, POSTFIX_SERVER, NOT_SEND_EMAIL
|
||||||
SUPPORT_EMAIL,
|
|
||||||
ROOT_DIR,
|
|
||||||
POSTFIX_SERVER,
|
|
||||||
ADMIN_EMAIL,
|
|
||||||
NOT_SEND_EMAIL,
|
|
||||||
)
|
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +19,7 @@ def _render(template_name, **kwargs) -> str:
|
||||||
|
|
||||||
|
|
||||||
def send_welcome_email(email, name):
|
def send_welcome_email(email, name):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
email,
|
email,
|
||||||
f"{name}, welcome to SimpleLogin!",
|
f"{name}, welcome to SimpleLogin!",
|
||||||
_render("welcome.txt", name=name),
|
_render("welcome.txt", name=name),
|
||||||
|
@ -34,7 +28,7 @@ def send_welcome_email(email, name):
|
||||||
|
|
||||||
|
|
||||||
def send_activation_email(email, name, activation_link):
|
def send_activation_email(email, name, activation_link):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
email,
|
email,
|
||||||
f"{name}, just one more step to join SimpleLogin",
|
f"{name}, just one more step to join SimpleLogin",
|
||||||
_render(
|
_render(
|
||||||
|
@ -47,7 +41,7 @@ def send_activation_email(email, name, activation_link):
|
||||||
|
|
||||||
|
|
||||||
def send_reset_password_email(email, name, reset_password_link):
|
def send_reset_password_email(email, name, reset_password_link):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
email,
|
email,
|
||||||
f"{name}, reset your password on SimpleLogin",
|
f"{name}, reset your password on SimpleLogin",
|
||||||
_render(
|
_render(
|
||||||
|
@ -60,7 +54,7 @@ def send_reset_password_email(email, name, reset_password_link):
|
||||||
|
|
||||||
|
|
||||||
def send_change_email(new_email, current_email, name, link):
|
def send_change_email(new_email, current_email, name, link):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
new_email,
|
new_email,
|
||||||
f"{name}, confirm email update on SimpleLogin",
|
f"{name}, confirm email update on SimpleLogin",
|
||||||
_render(
|
_render(
|
||||||
|
@ -81,7 +75,7 @@ def send_change_email(new_email, current_email, name, link):
|
||||||
|
|
||||||
|
|
||||||
def send_new_app_email(email, name):
|
def send_new_app_email(email, name):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
email,
|
email,
|
||||||
f"{name}, any questions/feedbacks for SimpleLogin?",
|
f"{name}, any questions/feedbacks for SimpleLogin?",
|
||||||
_render("new-app.txt", name=name),
|
_render("new-app.txt", name=name),
|
||||||
|
@ -90,7 +84,7 @@ def send_new_app_email(email, name):
|
||||||
|
|
||||||
|
|
||||||
def send_test_email_alias(email, name):
|
def send_test_email_alias(email, name):
|
||||||
send_by_postfix(
|
send_email(
|
||||||
email,
|
email,
|
||||||
f"{name}, this email is sent to {email}",
|
f"{name}, this email is sent to {email}",
|
||||||
_render("test-email.txt", name=name, alias=email),
|
_render("test-email.txt", name=name, alias=email),
|
||||||
|
@ -98,7 +92,7 @@ def send_test_email_alias(email, name):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def send_by_postfix(to_email, subject, plaintext, html):
|
def send_email(to_email, subject, plaintext, html):
|
||||||
if NOT_SEND_EMAIL:
|
if NOT_SEND_EMAIL:
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"send email with subject %s to %s, plaintext: %s, html:%s",
|
"send email with subject %s to %s, plaintext: %s, html:%s",
|
||||||
|
@ -132,10 +126,6 @@ def send_by_postfix(to_email, subject, plaintext, html):
|
||||||
smtp.send_message(msg, from_addr=SUPPORT_EMAIL, to_addrs=[to_email])
|
smtp.send_message(msg, from_addr=SUPPORT_EMAIL, to_addrs=[to_email])
|
||||||
|
|
||||||
|
|
||||||
def notify_admin(subject, html_content=""):
|
|
||||||
send_by_postfix(ADMIN_EMAIL, subject, html_content, html_content)
|
|
||||||
|
|
||||||
|
|
||||||
def get_email_name(email_from):
|
def get_email_name(email_from):
|
||||||
"""parse email from header and return the name part
|
"""parse email from header and return the name part
|
||||||
First Last <ab@cd.com> -> First Last
|
First Last <ab@cd.com> -> First Last
|
||||||
|
|
16
cron.py
16
cron.py
|
@ -1,7 +1,7 @@
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
from app import email_utils
|
from app.config import IGNORED_EMAILS, ADMIN_EMAIL
|
||||||
from app.config import IGNORED_EMAILS
|
from app.email_utils import send_email
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import (
|
from app.models import (
|
||||||
|
@ -18,6 +18,10 @@ from server import create_app
|
||||||
|
|
||||||
def stats():
|
def stats():
|
||||||
"""send admin stats everyday"""
|
"""send admin stats everyday"""
|
||||||
|
if not ADMIN_EMAIL:
|
||||||
|
# nothing to do
|
||||||
|
return
|
||||||
|
|
||||||
# nb user
|
# nb user
|
||||||
q = User.query
|
q = User.query
|
||||||
for ie in IGNORED_EMAILS:
|
for ie in IGNORED_EMAILS:
|
||||||
|
@ -68,9 +72,11 @@ def stats():
|
||||||
|
|
||||||
today = arrow.now().format()
|
today = arrow.now().format()
|
||||||
|
|
||||||
email_utils.notify_admin(
|
send_email(
|
||||||
f"SimpleLogin Stats for {today}",
|
ADMIN_EMAIL,
|
||||||
f"""
|
subject=f"SimpleLogin Stats for {today}",
|
||||||
|
plaintext="",
|
||||||
|
html=f"""
|
||||||
Stats for {today} <br>
|
Stats for {today} <br>
|
||||||
|
|
||||||
nb_user: {nb_user} <br>
|
nb_user: {nb_user} <br>
|
||||||
|
|
|
@ -39,7 +39,7 @@ from smtplib import SMTP
|
||||||
from aiosmtpd.controller import Controller
|
from aiosmtpd.controller import Controller
|
||||||
|
|
||||||
from app.config import EMAIL_DOMAIN, POSTFIX_SERVER, URL
|
from app.config import EMAIL_DOMAIN, POSTFIX_SERVER, URL
|
||||||
from app.email_utils import get_email_name, get_email_part, send_by_postfix
|
from app.email_utils import get_email_name, get_email_part, send_email
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import GenEmail, ForwardEmail, ForwardEmailLog
|
from app.models import GenEmail, ForwardEmail, ForwardEmailLog
|
||||||
|
@ -223,7 +223,7 @@ class MailHandler:
|
||||||
user_email,
|
user_email,
|
||||||
)
|
)
|
||||||
|
|
||||||
send_by_postfix(
|
send_email(
|
||||||
envelope.mail_from,
|
envelope.mail_from,
|
||||||
f"Your email ({envelope.mail_from}) is not allowed to send email to {reply_email}",
|
f"Your email ({envelope.mail_from}) is not allowed to send email to {reply_email}",
|
||||||
"",
|
"",
|
||||||
|
|
Loading…
Reference in New Issue