dev: email configuration settings moved to database

This commit is contained in:
pablohashescobar 2023-11-09 12:32:34 +05:30
parent b90218580d
commit 216f07f9d8
8 changed files with 87 additions and 34 deletions

View File

@ -18,15 +18,6 @@ REDIS_HOST="plane-redis"
REDIS_PORT="6379"
REDIS_URL="redis://${REDIS_HOST}:6379/"
# Email Settings
EMAIL_HOST=""
EMAIL_HOST_USER=""
EMAIL_HOST_PASSWORD=""
EMAIL_PORT=587
EMAIL_FROM="Team Plane <team@mailer.plane.so>"
EMAIL_USE_TLS="1"
EMAIL_USE_SSL="0"
# AWS Settings
AWS_REGION=""
AWS_ACCESS_KEY_ID="access-key"

View File

@ -3,7 +3,7 @@ import csv
import io
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -16,6 +16,7 @@ from sentry_sdk import capture_exception
from plane.db.models import Issue
from plane.utils.analytics_plot import build_graph_plot
from plane.utils.issue_filters import issue_filters
from plane.license.models import InstanceConfiguration
row_mapping = {
"state__name": "State",
@ -47,7 +48,19 @@ def send_export_email(email, slug, csv_buffer):
text_content = strip_tags(html_content)
csv_buffer.seek(0)
msg = EmailMultiAlternatives(subject, text_content, settings.EMAIL_FROM, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach(f"{slug}-analytics.csv", csv_buffer.getvalue())
msg.send(fail_silently=False)

View File

@ -1,5 +1,5 @@
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -11,8 +11,7 @@ from celery import shared_task
from sentry_sdk import capture_exception
# Module imports
from plane.db.models import User
from plane.license.models import InstanceConfiguration
@shared_task
def email_verification(first_name, email, token, current_site):
@ -34,7 +33,18 @@ def email_verification(first_name, email, token, current_site):
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
# Initiate email alternatives
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach_alternative(html_content, "text/html")
msg.send()
return

View File

@ -1,5 +1,5 @@
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -8,6 +8,8 @@ from django.conf import settings
from celery import shared_task
from sentry_sdk import capture_exception
# Module imports
from plane.license.models import InstanceConfiguration
@shared_task
@ -30,7 +32,18 @@ def forgot_password(first_name, email, uidb64, token, current_site):
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
# Initiate email alternatives
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach_alternative(html_content, "text/html")
msg.send()
return

View File

@ -1,5 +1,5 @@
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -8,6 +8,8 @@ from django.conf import settings
from celery import shared_task
from sentry_sdk import capture_exception
# Module imports
from plane.license.models import InstanceConfiguration
@shared_task
def magic_link(email, key, token, current_site):
@ -25,7 +27,18 @@ def magic_link(email, key, token, current_site):
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
# Initiate email alternatives
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach_alternative(html_content, "text/html")
msg.send()
return

View File

@ -1,5 +1,5 @@
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -10,6 +10,7 @@ from sentry_sdk import capture_exception
# Module imports
from plane.db.models import Project, User, ProjectMemberInvite
from plane.license.models import InstanceConfiguration
@shared_task
@ -43,7 +44,18 @@ def project_invitation(email, project_id, token, current_site):
project_member_invite.message = text_content
project_member_invite.save()
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
# Initiate email alternatives
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach_alternative(html_content, "text/html")
msg.send()
return

View File

@ -1,5 +1,5 @@
# Django imports
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
@ -12,7 +12,7 @@ from slack_sdk.errors import SlackApiError
# Module imports
from plane.db.models import Workspace, WorkspaceMemberInvite
from plane.license.models import InstanceConfiguration
@shared_task
def workspace_invitation(email, workspace_id, token, current_site, invitor):
@ -47,7 +47,18 @@ def workspace_invitation(email, workspace_id, token, current_site, invitor):
workspace_member_invite.message = text_content
workspace_member_invite.save()
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
# Configure email connection from the database
instance_configuration = InstanceConfiguration.objects.filter(key__startswith='EMAIL_').values()
connection = get_connection(
host=instance_configuration.get("EMAIL_HOST", ""),
port=int(instance_configuration.get("EMAIL_PORT", "587")),
username=instance_configuration.get("EMAIL_HOST_USER", ""),
password=instance_configuration.get("EMAIL_HOST_PASSWORD", ""),
use_tls=bool(instance_configuration.get("EMAIL_USE_TLS", "")),
use_ssl=bool(instance_configuration.get("EMAIL_USE_SSL", ""))
)
# Initiate email alternatives
msg = EmailMultiAlternatives(subject=subject, text_content=text_content, from_email=settings.EMAIL_FROM, to=[email], connection=connection)
msg.attach_alternative(html_content, "text/html")
msg.send()

View File

@ -173,16 +173,6 @@ USE_TZ = True
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
# Host for sending e-mail.
EMAIL_HOST = os.environ.get("EMAIL_HOST")
# Port for sending e-mail.
EMAIL_PORT = int(os.environ.get("EMAIL_PORT", 587))
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS", "1") == "1"
EMAIL_USE_SSL = os.environ.get("EMAIL_USE_SSL", "0") == "1"
EMAIL_FROM = os.environ.get("EMAIL_FROM", "Team Plane <team@mailer.plane.so>")
SIMPLE_JWT = {