define separate email for admin and mail sender

This commit is contained in:
deflax 2024-04-03 19:32:33 +03:00
parent 413500c53f
commit dc6c3e0a31
4 changed files with 7 additions and 6 deletions

View file

@ -14,10 +14,12 @@ POSTGRES_DB=forest_prod
PGADMIN_DEFAULT_EMAIL=mail@example.com
PGADMIN_DEFAULT_PASSWORD=hackme
MAIL_ADMIN=mail@example.com
MAIL_SENDER=mail@example.com
MAIL_SUBJECT_PREFIX=ForestNet
MAIL_SERVER=smtp.gmail.com
MAIL_USERNAME=admin@gmail.com
MAIL_PASSWORD=kur
MAIL_PORT=25
MAIL_USE_TLS=1
ADMIN_MAIL=mail@example.com

View file

@ -1,9 +1,7 @@
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
SECRET_KEY = f"{os.getenv('SECRET_KEY')}"
RECAPTCHA_PUBLIC_KEY = f"{os.getenv('RECAPTCHA_PUBLIC_KEY')}"
@ -13,10 +11,11 @@ class Config(object):
STATIC_FOLDER = f"{os.getenv('APP_HOME')}/forest/static"
MEDIA_FOLDER = f"{os.getenv('APP_HOME')}/forest/media"
ADMIN_PREFIX = "fadmin"
MAIL_SENDER = f"{os.getenv('MAIL_SENDER')}"
MAIL_SERVER = f"{os.getenv('MAIL_SERVER')}"
MAIL_USERNAME = f"{os.getenv('MAIL_USERNAME')}"
MAIL_PASSWORD = f"{os.getenv('MAIL_PASSWORD')}"
MAIL_PORT = f"{os.getenv('MAIL_PORT')}"
MAIL_SUBJECT_PREFIX = f"{os.getenv('MAIL_SUBJECT_PREFIX')}"
MAIL_ADMIN = f"{os.getenv('MAIL_ADMIN')}"
MAIL_USE_TLS = f"{os.getenv('MAIL_USE_TLS')}"
ADMIN_MAIL = f"{os.getenv('ADMIN_MAIL')}"

View file

@ -16,7 +16,7 @@ def send_email(to, subject, template, **kwargs):
else:
newsubject = subject
app = current_app._get_current_object()
msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + newsubject, sender=app.config['MAIL_ADMIN'], recipients=[to])
msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + newsubject, sender=app.config['MAIL_SENDER'], recipients=[to])
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
thr = Thread(target=send_async_email, args=[app, msg])

View file

@ -88,7 +88,7 @@ class User(db.Model, UserMixin):
super(User, self).__init__(**kwargs)
if self.role is None:
if self.email == current_app.config['MAIL_ADMIN']:
if self.email == current_app.config['ADMIN_MAIL']:
#if email match config admin name create admin user
self.role = Role.query.filter_by(permissions=0xff).first()
if self.role is None: