full auto: freereg voucher claim, domain list, aqbh slider unlock, self-hosted mail_catcher MX (eu.cc denylisted on ForwardEmail), dns_clean jx_del, dns mode prio 5
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# mail_catcher — self-hosted catch-all MX
|
||||
|
||||
ForwardEmail (and most free catch-all relays) **denylist the whole `eu.cc` zone**,
|
||||
so `--mail fwd` does not deliver for these domains. This catcher replaces it with
|
||||
your own MX on any VPS with inbound port 25 open.
|
||||
|
||||
## How it works
|
||||
1. DNS: `A mail.<yourdomain> = VPS_IP`, `MX @ = mail.<yourdomain> (prio 5)`.
|
||||
2. `catcher.py` listens on `0.0.0.0:25`, accepts mail for **any address / any domain**.
|
||||
3. Each message is stored as `.eml` under `mail/` and relayed to your Gmail
|
||||
(SMTP_SSL 465, app password from `env.json`) with subject `[catch <rcpt>] <orig subject>`,
|
||||
so existing IMAP code-readers (`gname_core.imap_code`, dashboard inbox) see OTPs instantly.
|
||||
|
||||
## Deploy (Ubuntu 22.04+/Debian, root)
|
||||
```
|
||||
mkdir -p /root/mailcatch && cp catcher.py /root/mailcatch/
|
||||
pip3 install --break-system-packages aiosmtpd
|
||||
cat > /root/mailcatch/env.json <<'EOF'
|
||||
{"gm": "you@gmail.com", "gp": "your-gmail-app-password"}
|
||||
EOF
|
||||
chmod 600 /root/mailcatch/env.json
|
||||
# systemd unit:
|
||||
cat > /etc/systemd/system/mailcatch.service <<'EOF'
|
||||
[Unit]
|
||||
Description=Mail catch-all MX server
|
||||
After=network.target
|
||||
[Service]
|
||||
WorkingDirectory=/root/mailcatch
|
||||
ExecStart=/usr/bin/python3 /root/mailcatch/catcher.py
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload && systemctl enable --now mailcatch
|
||||
```
|
||||
|
||||
## Point your domains at it (from this toolkit)
|
||||
```
|
||||
python setup_dns.py yourdomain.eu.cc --a "mail=VPS_IP" --mx "@=mail.yourdomain.eu.cc:5"
|
||||
```
|
||||
Or one-command: `DNS_A_IP=VPS_IP python auto.py --domains 3 --mail dns`.
|
||||
|
||||
## Verify
|
||||
```
|
||||
# port open from the internet (not from ISPs that block 25, e.g. home lines):
|
||||
curl -s "https://check-host.net/check-tcp?host=VPS_IP:25&max_nodes=3" -H "Accept: application/json"
|
||||
# send a test to the VPS directly (bypasses DNS):
|
||||
python3 -c "import smtplib;s=smtplib.SMTP('VPS_IP',25);s.sendmail('t@t.t',['otp@test.yourdomain.eu.cc'],'Subject: t\r\n\r\nhi');s.quit()"
|
||||
journalctl -u mailcatch -n 5 # should log '(relayed)'
|
||||
```
|
||||
|
||||
Proven: gname `.eu.cc` domains → VPS MX → Gmail inbox, verification code visible in body
|
||||
(subject `[catch otp-...@domain]`), stored `.eml` on the box.
|
||||
@@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Catch-all MX server for your own domains (self-hosted, ForwardEmail-free).
|
||||
|
||||
Runs on port 25, accepts mail for ANY address on ANY domain pointed at this box,
|
||||
stores the .eml under MAIL_DIR and relays a readable copy to a Gmail inbox
|
||||
(SMTP_SSL 465, app password) so OTP codes land where your IMAP readers look.
|
||||
|
||||
Deploy: see mail_catcher/README.md — systemd unit + env.json {gm, gp}.
|
||||
Env file format (JSON): {"gm": "you@gmail.com", "gp": "app-password"} # optional
|
||||
"""
|
||||
import asyncio, json, os, re, smtplib, ssl, time
|
||||
from email.mime.message import MIMEMessage
|
||||
from email.mime.text import MIMEText
|
||||
import email as eml
|
||||
from aiosmtpd.controller import Controller
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
MAIL_DIR = os.path.join(BASE, "mail")
|
||||
ENV_FILE = os.path.join(BASE, "env.json")
|
||||
os.makedirs(MAIL_DIR, exist_ok=True)
|
||||
|
||||
|
||||
def load_env():
|
||||
try:
|
||||
with open(ENV_FILE, encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def relay_to_gmail(rcpts, raw: bytes):
|
||||
env = load_env()
|
||||
gm, gp = env.get("gm", ""), env.get("gp", "")
|
||||
if not gm or not gp:
|
||||
return "no-relay-creds"
|
||||
try:
|
||||
orig = eml.message_from_bytes(raw)
|
||||
subj = str(orig.get("Subject", ""))[:120]
|
||||
frm = str(orig.get("From", ""))[:120]
|
||||
wrap = MIMEText(
|
||||
"Caught for: %s\nFrom: %s\nSubject: %s\nTime: %s\n\n----- ORIGINAL MESSAGE -----\n\n%s"
|
||||
% (", ".join(rcpts)[:300], frm, subj, time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
orig.as_string()[:60000]),
|
||||
"plain", "utf-8")
|
||||
wrap["Subject"] = "[catch %s] %s" % (rcpts[0][:60], subj)
|
||||
wrap["From"] = gm
|
||||
wrap["To"] = gm
|
||||
s = smtplib.SMTP_SSL("smtp.gmail.com", 465, timeout=45,
|
||||
context=ssl.create_default_context())
|
||||
s.login(gm, gp)
|
||||
s.sendmail(gm, [gm], wrap.as_string())
|
||||
s.quit()
|
||||
return "relayed"
|
||||
except Exception as e:
|
||||
return "relay-fail: %s %s" % (type(e).__name__, str(e)[:100])
|
||||
|
||||
|
||||
class CatchAll:
|
||||
async def handle_RCPT(self, server, session, envelope, address, rcpt_options):
|
||||
envelope.rcpt_tos.append(address)
|
||||
return "250 OK"
|
||||
|
||||
async def handle_DATA(self, server, session, envelope):
|
||||
rcpts = list(envelope.rcpt_tos)
|
||||
raw = envelope.content
|
||||
if isinstance(raw, str):
|
||||
raw = raw.encode("utf-8", "replace")
|
||||
ts = time.strftime("%Y%m%d-%H%M%S")
|
||||
safe = re.sub(r"[^A-Za-z0-9@._-]", "_", rcpts[0] if rcpts else "none")[:80]
|
||||
path = os.path.join(MAIL_DIR, "%s_%s.eml" % (ts, safe))
|
||||
with open(path, "wb") as f:
|
||||
f.write(raw)
|
||||
status = relay_to_gmail(rcpts, raw)
|
||||
print("[catch] %s -> %s (%s) %d bytes" % (envelope.mail_from, rcpts, status, len(raw)), flush=True)
|
||||
return "250 Message accepted for delivery"
|
||||
|
||||
|
||||
def main():
|
||||
host = os.environ.get("CATCH_HOST", "0.0.0.0")
|
||||
port = int(os.environ.get("CATCH_PORT", "25"))
|
||||
c = Controller(CatchAll(), hostname=host, port=port, server_hostname="mail.local")
|
||||
c.start()
|
||||
print("[catch] listening on %s:%d, maildir=%s" % (host, port, MAIL_DIR), flush=True)
|
||||
try:
|
||||
while True:
|
||||
time.sleep(3600)
|
||||
except KeyboardInterrupt:
|
||||
c.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user