* support running backend + frontend together on k8s * split nginx container into separate frontend service, which uses nignx-base image and the static frontend files * add nginx-based frontend image to docker-compose build (for building only, docker-based combined deployment not yet supported) * backend: - fix paths for email templates - chart: support '--set backend_only=1' and '--set frontend_only=1' to only force deploy one or the other - run backend from root /api in uvicorn
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
""" Basic Email Sending Support"""
|
|
|
|
import os
|
|
import smtplib
|
|
import ssl
|
|
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
class EmailSender:
|
|
"""SMTP Email Sender"""
|
|
|
|
def __init__(self):
|
|
self.sender = os.environ.get("EMAIL_SENDER")
|
|
self.password = os.environ.get("EMAIL_PASSWORD")
|
|
self.smtp_server = os.environ.get("EMAIL_SMTP_HOST")
|
|
|
|
self.host = os.environ.get("APP_ORIGIN")
|
|
|
|
def _send_encrypted(self, receiver, message):
|
|
"""Send Encrypted SMTP Message"""
|
|
print(message, flush=True)
|
|
|
|
if not self.smtp_server:
|
|
print("Email: No SMTP Server, not sending", flush=True)
|
|
return
|
|
|
|
context = ssl.create_default_context()
|
|
with smtplib.SMTP(self.smtp_server, 587) as server:
|
|
server.ehlo() # Can be omitted
|
|
server.starttls(context=context)
|
|
server.ehlo() # Can be omitted
|
|
server.login(self.sender, self.password)
|
|
server.sendmail(self.sender, receiver, message)
|
|
|
|
def send_user_validation(self, receiver_email, token):
|
|
"""Send email to validate registration email address"""
|
|
message = f"""
|
|
Please verify your registration for Browsertrix Cloud for {receiver_email}
|
|
|
|
You can verify by clicking here: {self.host}/verify?token={token}
|
|
|
|
The verification token is: {token}"""
|
|
|
|
self._send_encrypted(receiver_email, message)
|
|
|
|
def send_new_user_invite(self, receiver_email, sender, archive_name, token):
|
|
"""Send email to invite new user"""
|
|
|
|
message = f"""
|
|
You are invited by {sender} to join their archive, {archive_name} on Browsertrix Cloud!
|
|
|
|
You can join by clicking here: {self.host}/join/{token}?email={receiver_email}
|
|
|
|
The invite token is: {token}"""
|
|
|
|
self._send_encrypted(receiver_email, message)
|
|
|
|
def send_user_forgot_password(self, receiver_email, token):
|
|
"""Send password reset email with token"""
|
|
message = f"""
|
|
We received your password reset request. Please click here: {self.host}/reset-password?token={token}
|
|
to create a new password
|
|
"""
|
|
|
|
self._send_encrypted(receiver_email, message)
|