campaign builder: send test email to carrierone@gmx.com per campaign before real blast
Each of the 8 daily campaigns gets a test send immediately after creation using the first row's real carrier data as the sample. TEST_EMAIL env var overrides the default (carrierone@gmx.com). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b66b5a4cdc
commit
03702dfbb7
1 changed files with 31 additions and 0 deletions
|
|
@ -65,6 +65,9 @@ TIMEZONE_CONFIG = {
|
|||
},
|
||||
}
|
||||
|
||||
# Owner email — test sends go here before each campaign is scheduled
|
||||
TEST_EMAIL = os.getenv("CAMPAIGN_TEST_EMAIL", "carrierone@gmx.com")
|
||||
|
||||
USABLE_FILTER = (
|
||||
"(email_verified IS TRUE OR email_verify_result IN "
|
||||
"('smtp_valid','catch_all_domain','catch_all_detected'))"
|
||||
|
|
@ -138,6 +141,31 @@ def create_and_schedule_campaign(
|
|||
return cid
|
||||
|
||||
|
||||
def send_test(base: dict, campaign_id: int, sample_row: tuple, label: str, tz: str) -> None:
|
||||
"""Send one test email so the owner can approve before the real blast goes out."""
|
||||
dot, email, name, state = sample_row
|
||||
body = base["body"]
|
||||
body = body.replace("{{ .Subscriber.Attribs.company }}", name or "Sample Carrier LLC")
|
||||
body = body.replace("{{ .Subscriber.Attribs.dot_number }}", dot or "0000000")
|
||||
body = body.replace("{{ .Subscriber.Attribs.state }}", state or "TX")
|
||||
body = body.replace("{{ UnsubscribeURL }}", "https://performancewest.net/unsubscribe")
|
||||
subj = base["subject"].replace("{{ .Subscriber.Attribs.dot_number }}", dot or "0000000")
|
||||
payload = {
|
||||
"name": base.get("name", ""), "subject": subj,
|
||||
"lists": base.get("lists", []), "from_email": base["from_email"],
|
||||
"type": base.get("type", "regular"), "content_type": base["content_type"],
|
||||
"body": body, "altbody": base.get("altbody"),
|
||||
"template_id": base["template_id"],
|
||||
"tags": base.get("tags") or [], "messenger": base.get("messenger") or "email",
|
||||
"subscribers": [TEST_EMAIL],
|
||||
}
|
||||
try:
|
||||
lm_api(f"/campaigns/{campaign_id}/test", payload, "POST")
|
||||
LOG.info("[%s/%s] Test sent to %s (sample: %s DOT#%s)", tz, label, TEST_EMAIL, name, dot)
|
||||
except Exception as exc:
|
||||
LOG.warning("[%s/%s] Test send failed: %s", tz, label, exc)
|
||||
|
||||
|
||||
def fetch_carriers(
|
||||
conn,
|
||||
tz_states: tuple,
|
||||
|
|
@ -243,6 +271,9 @@ def run(send_date: date, dry_run: bool = False) -> None:
|
|||
cid = create_and_schedule_campaign(base, list_id, campaign_name, send_at)
|
||||
LOG.info("[%s/%s] Campaign %d scheduled for %s UTC", tz, campaign_type, cid, send_at.isoformat())
|
||||
|
||||
# Send a test to the owner so they can spot-check before the blast fires
|
||||
send_test(base, cid, rows[0], label, tz)
|
||||
|
||||
# Mark carriers as sent in DB
|
||||
dot_numbers = [row[0] for row in rows]
|
||||
mark_sent(conn, dot_numbers, campaign_type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue