#!/usr/bin/env python3
import smtplib, ssl, os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

USER, APP = [x.strip() for x in open(os.path.expanduser("~/.aura_csi_smtp")).read().split("\n")[:2]]
TO   = "bob.carella@auravision.co"
CC   = "plchou@gmail.com"          # Paul — in the loop, he directed this
DIST = "0x58f8703C7051283811807BdB4d169C349Fa39FCe"

plain = f"""Bob,

Urgent and time-sensitive. The card payments for the current launch have already
settled into Stripe — the cash for these orders is in hand — but our on-chain
delivery reserve is nearly empty, so paid buyers are about to stop receiving
their $LEDGER.

Where it stands right now:
  - Distributor {DIST} reserve: ~1.72M $LEDGER (~$398)
  - Launch orders to date: 30 / $5,335.86, still converting
  - Headroom: ~3 more orders before deliveries stall and buyers are left waiting

Since the payments have landed, nothing is gating this but inventory. Please top
up the distributor now — at least ~25M $LEDGER (~$5,800) to clear the current
launch with a buffer, and more if you can, since it's still converting. The
moment it lands, every held order delivers automatically.

  Send $LEDGER to: {DIST}  (Ethereum mainnet)

A paid buyer not receiving their tokens is the one failure we can't have mid-launch.
Flag me the tx once it's out and I'll confirm the queue clears.

Aura (CSI)
"""

html = f"""<div style="font-family:'Chakra Petch',-apple-system,Segoe UI,sans-serif;font-size:15px;color:#1a1510;line-height:1.6">
<p>Bob,</p>
<p><b>Urgent and time-sensitive.</b> The card payments for the current launch have already
settled into Stripe — the cash for these orders is in hand — but our on-chain delivery
reserve is nearly empty, so paid buyers are about to stop receiving their $LEDGER.</p>
<p>Where it stands right now:</p>
<ul>
  <li>Distributor <code>{DIST}</code> reserve: <b>~1.72M $LEDGER (~$398)</b></li>
  <li>Launch orders to date: 30 / $5,335.86, still converting</li>
  <li>Headroom: <b>~3 more orders</b> before deliveries stall and buyers are left waiting</li>
</ul>
<p>Since the payments have landed, nothing is gating this but inventory. <b>Please top up the
distributor now</b> — at least <b>~25M $LEDGER (~$5,800)</b> to clear the current launch with a
buffer, and more if you can, since it's still converting. The moment it lands, every held order
delivers automatically.</p>
<p style="background:#faf4e8;border-left:3px solid #e8a84a;padding:10px 14px;font-family:monospace;font-size:14px">
Send $LEDGER to: <b>{DIST}</b> &nbsp;(Ethereum mainnet)</p>
<p>A paid buyer not receiving their tokens is the one failure we can't have mid-launch. Flag me
the tx once it's out and I'll confirm the queue clears.</p>
<p style="margin-top:18px">Aura <span style="color:#8a7a5c">(CSI)</span></p>
</div>"""

m = MIMEMultipart("alternative")
m["Subject"] = "Action needed now — distributor $LEDGER reserve critically low"
m["From"] = f"Aura (CSI) <{USER}>"
m["To"] = TO
m["Cc"] = CC
m.attach(MIMEText(plain, "plain"))
m.attach(MIMEText(html, "html"))

ctx = ssl.create_default_context()
s = smtplib.SMTP("smtp.gmail.com", 587, timeout=60)
s.ehlo(); s.starttls(context=ctx); s.ehlo(); s.login(USER, APP)
s.sendmail(USER, [TO, CC], m.as_string()); s.quit()
print(f"SENT from {USER} -> to {TO}, cc {CC}")
