stop using mailgun

master
Aevann 2023-01-21 02:19:07 +02:00
parent e361ac5ea5
commit eae3f51c56
6 changed files with 37 additions and 16 deletions

View File

@ -10,6 +10,7 @@ RUN apt install -y ffmpeg
RUN apt install -y postgresql RUN apt install -y postgresql
RUN apt install -y libpq-dev RUN apt install -y libpq-dev
RUN apt install -y nano RUN apt install -y nano
RUN apt install -y mailutils
COPY requirements.txt /etc/requirements.txt COPY requirements.txt /etc/requirements.txt

1
env
View File

@ -16,7 +16,6 @@ export VAPID_PRIVATE_KEY="blahblahblah"
export GUMROAD_TOKEN="blahblahblah" export GUMROAD_TOKEN="blahblahblah"
export GUMROAD_LINK="blahblahblah" export GUMROAD_LINK="blahblahblah"
export GUMROAD_ID="blahblahblah" export GUMROAD_ID="blahblahblah"
export MAILGUN_KEY="blahblahblah"
export CF_KEY="blahblahblah" export CF_KEY="blahblahblah"
export CF_ZONE="blahblahblah" export CF_ZONE="blahblahblah"
export DEBIAN_FRONTEND="noninteractive" export DEBIAN_FRONTEND="noninteractive"

View File

@ -45,7 +45,6 @@ VAPID_PRIVATE_KEY = environ.get("VAPID_PRIVATE_KEY").strip()
GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN").strip() GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN").strip()
GUMROAD_LINK = environ.get("GUMROAD_LINK").strip() GUMROAD_LINK = environ.get("GUMROAD_LINK").strip()
GUMROAD_ID = environ.get("GUMROAD_ID").strip() GUMROAD_ID = environ.get("GUMROAD_ID").strip()
MAILGUN_KEY = environ.get("MAILGUN_KEY").strip()
CF_KEY = environ.get("CF_KEY").strip() CF_KEY = environ.get("CF_KEY").strip()
CF_ZONE = environ.get("CF_ZONE").strip() CF_ZONE = environ.get("CF_ZONE").strip()
GLOBAL = environ.get("GLOBAL", "").strip() GLOBAL = environ.get("GLOBAL", "").strip()

View File

@ -2,14 +2,15 @@ import requests
import time import time
from files.helpers.security import * from files.helpers.security import *
from files.helpers.config.const import EMAIL, MAILGUN_KEY from files.helpers.config.const import EMAIL
from urllib.parse import quote from urllib.parse import quote
from flask import render_template from flask import render_template
def send_mail(to_address, subject, html):
if SITE == 'rdrama.net': if SITE == 'rdrama.net':
def send_mail(to_address, subject, html):
url = f"https://deuxrama.net/email" url = f"https://deuxrama.net/email"
data = {"from": EMAIL, data = {"from": EMAIL,
"to": to_address, "to": to_address,
@ -17,16 +18,36 @@ def send_mail(to_address, subject, html):
"html": html, "html": html,
} }
requests.post(url, data=data) requests.post(url, data=data)
else: else:
if MAILGUN_KEY == DEFAULT_CONFIG_VALUE: return import smtplib
url = f"https://api.mailgun.net/v3/{SITE}/messages" from email.mime.text import MIMEText
auth = ("api", MAILGUN_KEY) from email.utils import formatdate, make_msgid
data = {"from": EMAIL, import dkim
"to": [to_address],
"subject": subject, def send_mail(to_address, subject, html):
"html": html, msg = MIMEText(html, 'html')
}
requests.post(url, auth=auth, data=data) msg['Subject'] = subject
msg['From'] = EMAIL
msg['To'] = to_address
msg['Date'] = formatdate()
msg['Message-ID'] = make_msgid(domain=SITE)
headers = ["To", "From", "Subject", "Message-ID"]
with open("/dkim_private.pem") as fh:
dkim_private = fh.read()
sig = dkim.sign(
message=msg.as_string().encode("ascii"),
selector='d'.encode("ascii"),
domain=SITE.encode("ascii"),
privkey=dkim_private.encode("ascii"),
include_headers=headers
)
msg["DKIM-Signature"] = sig.decode("ascii").lstrip("DKIM-Signature: ")
with smtplib.SMTP('localhost', 25) as server:
server.sendmail(EMAIL, [to_address], msg.as_string())
print(f"Successfully sent email to {to_address}", flush=True)
def send_verification_email(user, email=None): def send_verification_email(user, email=None):

View File

@ -1,6 +1,7 @@
beautifulsoup4 beautifulsoup4
bleach bleach
bleach[css] bleach[css]
dkimpy
Flask Flask
Flask-Caching Flask-Caching
Flask-Compress Flask-Compress

View File

@ -2,7 +2,7 @@
apt -y update apt -y update
apt -y upgrade apt -y upgrade
apt -y install git redis-server python3-pip ffmpeg tmux nginx snapd ufw gpg-agent htop nano apt -y install git redis-server python3-pip ffmpeg tmux nginx snapd ufw gpg-agent htop nano mailutils
git config --global credential.helper store git config --global credential.helper store
cd /rDrama cd /rDrama