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 libpq-dev
RUN apt install -y nano
RUN apt install -y mailutils
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_LINK="blahblahblah"
export GUMROAD_ID="blahblahblah"
export MAILGUN_KEY="blahblahblah"
export CF_KEY="blahblahblah"
export CF_ZONE="blahblahblah"
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_LINK = environ.get("GUMROAD_LINK").strip()
GUMROAD_ID = environ.get("GUMROAD_ID").strip()
MAILGUN_KEY = environ.get("MAILGUN_KEY").strip()
CF_KEY = environ.get("CF_KEY").strip()
CF_ZONE = environ.get("CF_ZONE").strip()
GLOBAL = environ.get("GLOBAL", "").strip()

View File

@ -2,14 +2,15 @@ import requests
import time
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 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"
data = {"from": EMAIL,
"to": to_address,
@ -17,16 +18,36 @@ def send_mail(to_address, subject, html):
"html": html,
}
requests.post(url, data=data)
else:
if MAILGUN_KEY == DEFAULT_CONFIG_VALUE: return
url = f"https://api.mailgun.net/v3/{SITE}/messages"
auth = ("api", MAILGUN_KEY)
data = {"from": EMAIL,
"to": [to_address],
"subject": subject,
"html": html,
}
requests.post(url, auth=auth, data=data)
else:
import smtplib
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
import dkim
def send_mail(to_address, subject, html):
msg = MIMEText(html, 'html')
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):

View File

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

View File

@ -2,7 +2,7 @@
apt -y update
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
cd /rDrama